Odpovědět How to control MediaElement playback with a Storyboard?

  • Monday, April 16, 2012 1:55 PM
     
     
    In Silverlight/WPF we had the MediaTimeLine, which allowed us to control a MediaElement's playback using a storyboard.  How can we accomplish this in a Metro app?  I want to control playback without using code-behind, strictly using binding.  Is this possible?

All Replies

  • Tuesday, April 17, 2012 12:27 PM
     
     
    This topic was moved by the moderator to the C#/VB forum, but I would like to reiterate that I am looking for a XAML-only approach to playing a sound, e.g. as part of a Storyboard.
  • Tuesday, April 17, 2012 9:55 PM
    Moderator
     
     

    Hello Gspence,

    You should be able to accomplish this by binding the position property of the timeline to the position property of the MediaElement. I seem to remember on the engineers I worked with in the past doing this successfully in SL. Please give this a try and let me know if you have any specific questions about the implementation and I will try to help you out.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

  • Wednesday, April 18, 2012 2:11 AM
     
     

    James,

    The MediaTimeLine that we had in Silverlight is not present in Metro, so I don't think there's anything to bind with the MediaElement's Position property.

    Thanks,

    gspence

  • Wednesday, April 18, 2012 7:43 PM
     
     
    You probably would have to create separate component (something like a behaviour) with dependency property that can be manipulated from story board and drive sound playback.
  • Thursday, April 19, 2012 10:57 PM
    Moderator
     
     Answered Has Code

    If you can figure out how to get the current position of the timeline you should be able to do something like this to bind to the MediaElement. Keep in mind that the ME current position is defined as a "TimeSpan" so you might need to write a converter.

    <MediaElement x:Name="_me" Position="{Binding Value}"/>

    I hope this helps,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/