WPF Video Source

I am trying to set the video source in XAML code, the video is not playing:

<MediaElement x:Name="bgvideo" Width="800" Height="600"Source="/Videos/BG_LOOP_BIG.wmv" />

Therefore, I am trying to set the video source to codebehind, which also does not play.

bgvideo.Source = new Uri(@"pack://application:,,,/Videos/BG_LOOP_BIG.wmv", UriKind.Absolute);

or

bgvideo.Source = new Uri(@"/Videos/BG_LOOP_BIG.wmv");

It just plays when the absoulte video source:

bgvideo.Source = new Uri(@"C:\SomeFolder\Videos\BG_LOOP_BIG.wmv");

How to set a video source with a relative source?

+3
source share
3 answers

This works for me. Add LoadedBehavior = "Manual"

<MediaElement LoadedBehavior="Manual" x:Name="bgvideo" Width="800" Height="600" Source="Videos/BG_LOOP_BIG.wmv" />

Then in the code behind you need to play the media

bgvideo.Play()

You also need to lose the first "/" in the uri.

Hth

+2
source
<MediaElement x:Name="bgvideo" Width="800" Height="600"Source="Videos/BG_LOOP_BIG.wmv" />

This also works, you just need to set the Copy property to output the directory of the video file to a copy if it is newer or always copy.

+2

:

:)

, , .

+1

Source: https://habr.com/ru/post/1705237/


All Articles