Murat
Murat

Reputation: 898

WPF Media Element Video Source

I try to set video source in XAML code, video doesn't play:

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

So I try to set video source in codebehind, that doesn't play too. :

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 play when video source is absoulte:

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

How can I set video source with relative source?

Upvotes: 4

Views: 31595

Answers (3)

tHien
tHien

Reputation: 21

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

This is also working, you just have to set the property Copy to output directory of the video file on copy if newer or copy always.

Upvotes: 2

Simon S&#246;derman
Simon S&#246;derman

Reputation: 335

Drop the first slash:

:)

also, as far as I know, Videos cannot be embedded into the assembly.

Upvotes: 1

PaulB
PaulB

Reputation: 24372

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

Upvotes: 3

Related Questions