Local playback of video using MediaElement


  • Hello,

    I'm trying to use C++ to build a metro app, and trying to have a video stored on my local harddrive play through a MediaElement.

    I'm using XAML to code my interface, and when I create the MediaElement and tell it where the video is, the preview shows the first frame of the video. However, when I run the code nothing starts.

    Here is the code for my MediaElement:


    <Grid x:Name="LayoutRoot" Background="#FF0C0C0C">
      <StackPanel Orientation="Horizontal" x:Name="stk">
        <MediaElement Source="S2.mp4" Width="1280" Height="720"></MediaElement>


    I'm wondering what is wrong. I'm just starting out with Metro Apps and XAML, so any help would be appreciated. (I've been strictly C++ before now, but I'm liking the ease of the UI using XAML so I'm trying it out)

    EDIT: I've been looking through the //build lab about playing media in Metro Apps and I'm still having a problem.

    EDIT2: I've figured it out. My initial code wasn't working obviously, and then I found the lab. The lab also wasn't working because for some reason when I tried to set the source of the video I was using '\\' and that wasn't working to denote a folder. I changed it to '/' and it worked fine.


    • Edited by DLAlex Monday, January 23, 2012 4:45 PM
    Monday, January 23, 2012 3:09 PM


All replies

  • Thanks for sharing your finding with the forum Alex!
    Tuesday, January 24, 2012 8:43 PM
  • Set the source of the video to '/' instead of using '\\'.
    James Windows Media SDK Technologies Microsoft Developer Services http://blogs.msdn.com/mediasdkstuff/
    Thursday, January 26, 2012 1:48 AM
  • Hi DLAlex,

    I got some problem ,I am trying to use C++ to play audio,Here is my code

    in Xaml:

    <MediaElement Source="msg.wav" AutoPlay="False" x:Name="AudioPlay"></MediaElement>

    in Cpp:


    It works well when I write in the c#,but It doesn't work when I write in C++.

    I find you have solved this problem, can you give me some suggestion? thank you

    Monday, March 26, 2012 4:09 AM
  • Hi,

    Are you using Consumer Preview? I've recently switched over to it, and now the code that worked in Developer Preview doesn't work anymore.

    Any news on this Mods?


    Monday, April 02, 2012 5:41 PM