views:

2460

answers:

3

Hello,

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?

A: 

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

PaulB
I already try this issue :I set LoadedBehavior="Manual" and Loaded event with "bgvideo_Loaded" event handler. I wrote bgvideo.Play() in bgvideo_Loaded method. Now;I removed first '/' and still not working :(
mrt
Have you got the wmv in bin/debug/Videos/?If you remove the LoadedBehavior attribute it should start playing automatically without the need to call Play().
PaulB
There is no Video folder in bin/debug :) I copied that, and it works :) Thank you so much. Why visual studio doesn't copy this folder in bin/debug, do you have any idea?
mrt
If you add a 'Video' folder to the project then pop your video in there and set it's 'Copy to Output' property to 'copy' it'll copy it down to the output folder for you.
PaulB
A: 

Drop the first slash:

:)

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

Simon Söderman
A: 

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..

tHien