简体   繁体   中英

Cannot play a relative mp4 video in a MediaElement WPF


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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM