WPF Media Element Video Source
30,494
Solution 1
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
Solution 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.
Solution 3
Drop the first slash:
:)
also, as far as I know, Videos cannot be embedded into the assembly.
Author by
Murat
Updated on August 05, 2022Comments
-
Murat almost 2 years
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 over 15 yearsI 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 :(
-
PaulB over 15 yearsHave 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().
-
Murat over 15 yearsThere 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?
-
PaulB over 15 yearsIf 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.
-
Nasenbaer almost 12 yearsdamn. 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!