Home > Blockchain >  Cannot play a relative mp4 video in a MediaElement WPF
Cannot play a relative mp4 video in a MediaElement WPF

Time:11-28


I'm trying to play a mp4 video in my media element in WPF.
The mp4 video is in a folder in my solution. I tried diffrent things but the only way it works is when i put the full path to the video in the uri.
What am i doing wrong?

XAML

<MediaElement x:Name="VideoDice" Grid.Row="2" Grid.Column="2" LoadedBehavior="Manual" MediaEnded="VideoDice_MediaEnded" VerticalAlignment="Bottom" HorizontalAlignment="Left"/> 

C#

VideoDice.Source = new Uri("DiceMovies/Dice_2.mp4", UriKind.Relative);
VideoDice.Height = 500;
VideoDice.Width = 500;
VideoDice.Play();

CodePudding user response:

In your project for the Dice_2.mp4 file it's necessary to set Copy to Output Directory property to Copy if newer. Looks like your .mp4 file does not copied to the output directory automatically.

  • Related