4

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?

Murat
  • 878
  • 3
  • 11
  • 19

3 Answers3

3

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
  • 23,264
  • 14
  • 56
  • 75
  • 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 :( – Murat Mar 24 '09 at 09:09
  • 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 Mar 24 '09 at 09:33
  • 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? – Murat Mar 24 '09 at 09:51
  • 3
    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 Mar 24 '09 at 10:09
  • damn. had the same issu since now 2 hours. First I thought it was the codec. When removing first "/" slash Visual Studio 2010 says: error, is not part of the project. But it just works perfect now. Just remove first "/" was my secret. thanks to your post! – Nasenbaer Aug 10 '12 at 23:05
2
<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.

Taryn
  • 242,637
  • 56
  • 362
  • 405
tHien
  • 21
  • 2
1

Drop the first slash:

:)

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

Simon Söderman
  • 335
  • 1
  • 7