Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play a video on WPF #9127

Closed
phanthanhdat077 opened this issue May 20, 2024 · 2 comments
Closed

Play a video on WPF #9127

phanthanhdat077 opened this issue May 20, 2024 · 2 comments

Comments

@phanthanhdat077
Copy link

I'm learning WPF and trying to make a Chat project and am having problems playing videos in WPF.I try with MediaElement but it slow and can not play a video from link : "https://beta.api.gateway.overate-vntech.com/s3/techres/keep/2024/05/18/videos/original/overate-vntech-37342-Bc33OhaNuCvJ8Xg8s5868.mp4" . Please someone help me about it! How can play a video on WPF like:
image

@singhashish-wpf
Copy link
Member

@phanthanhdat077 can you please provide your sample app and we can check and update if there is something?

@huiliuss
Copy link

1.Make sure the video link is accessible
Web video link: Enter the video link into your browser to access the video.

Local video link: The video can be opened locally and the link location is correct

I can't display the video link you gave me. Maybe it's a problem with the video. You can try a few more video links.

  1. Related code
<Grid Loaded="UserControl_Loaded">

    <MediaElement x:Name="mediaElement" />

</Grid>
public partial class MainWindow : Window

{

     public MainWindow()

     {

         InitializeComponent();

     }

 

     private void UserControl_Loaded(object sender, RoutedEventArgs e)

     {

         // Bind video files

         mediaElement.Source = new Uri([https://prod-streaming-video-msn-com.akamaized.net/a8c412fa-f696-4ff2-9c76-e8ed9cdffe0f/604a87fc-e7bc-463e-8d56-cde7e661d690.mp4](https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fprod-streaming-video-msn-com.akamaized.net%2Fa8c412fa-f696-4ff2-9c76-e8ed9cdffe0f%2F604a87fc-e7bc-463e-8d56-cde7e661d690.mp4&data=05%7C02%7Cv-huiliu1%40microsoft.com%7C70ca5a2e4bc84bf5f5fc08dc78b37fbd%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638517959546117408%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=aY0a8VfftilvsgCnGNmDYVUKPeMR96GuK3Bf8nfpH0I%3D&reserved=0));

 

         // Allow interactive control

         mediaElement.LoadedBehavior = MediaState.Manual;

         mediaElement.Loaded += new RoutedEventHandler(media_Loaded);

         mediaElement.Unloaded += new RoutedEventHandler(media_Unloaded);

         mediaElement.MediaEnded += new RoutedEventHandler(media_MediaEnded);

     }

 

     private void media_Loaded(object sender, RoutedEventArgs e)

     {

         (sender as MediaElement).Play();

     }

 

     private void media_Unloaded(object sender, RoutedEventArgs e)

     {

         (sender as MediaElement).Stop();

     }

 

     private void media_MediaEnded(object sender, RoutedEventArgs e)

     {

         (sender as MediaElement).Stop();

         (sender as MediaElement).Play();

     }

}

@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback To request more information from author. label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants