Recommended

  • Silverlight.FX
    Silverlight.FX is a light-weight application framework for building RichInternet Applications with Silverlight 2.
  • Building Modular Silverlight Applications
  • Prism -  10 Things to Know
  • Securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques
  • Model– View – ViewModel in Silverlight

Silverlight Hosting

Skip Navigation LinksHome / Articles / View Article

Silverlight 2, Databinding to the MediaElement.Position property

+ Add to SilverlightShow Favorites
3 comments   /   aggregated from Mike Taulty's Blog on Apr 15, 2008  /  original article
(0 votes)
Categories: Tips and Tricks

In a word, don't :-)

MediaElement.Position is very attractive because it's pretty common to display some UI to show an indicator displaying where you're up to within a particular video.

MediaElement.Position is of type TimeSpan and it's a DependencyProperty so it looks ripe for binding. However, it won't work.

I've asked around and one of the reasons why it doesn't work is that it's actually quite a high resolution value ( I'm advised of the order tracking at 100ns intervals ) and so if you databound to it then you'd be getting an awful lot of updates.

So...if you need to display where you're up to within a video then it might be advisable to use a Storyboard that goes from 0 to the duration of the video and animate some property (e.g. value of a thumb on a slider) based on that.

Alternatively, you could use a timer and poll the Position value every so often.

Share


Comments

Comments RSS RSS
  • RE: Silverlight 2, Databinding to the MediaElement.Position property - Performance issues of binding vs direct  

    posted by Gavroche on Jun 24, 2009 17:51
    There is also a performance hit if you use binding to set the position instead of setting the Position property directly. I wrote a test app to prove this as I couldn't (and still can't) understand why this might be! Perhaps someone can shed some light?

    I want to step through a movie - so  I set up a timer to increment the position (each 100ms originally, then each 1s).  The Binding method is a lot slower. Looking at TaskManager the cpu usage with binding looks like a comb  with 100% cpu usage at least half the time. Using property, there are maybe only a few times when the cpu goes 100%, although when it does the pc is still just about locked. I'm playing H264 FWIW but it came out of a converter app I found on the web and is massively inefficient - 20s of low res AV is over 2 MB! 

     

     


  • RE: Silverlight 2, Databinding to the MediaElement.Position property  

    posted by Gavroche on Jun 24, 2009 17:52
    There is also a performance hit if you use binding to set the position instead of setting the Position property directly. I wrote a test app to prove this as I couldn't (and still can't) understand why this might be! Perhaps someone can shed some light?

    I want to step through a movie - so  I set up a timer to increment the position (each 100ms originally, then each 1s).  The Binding method is a lot slower. Looking at TaskManager the cpu usage with binding looks like a comb  with 100% cpu usage at least half the time. Using property, there are maybe only a few times when the cpu goes 100%, although when it does the pc is still just about locked. I'm playing H264 FWIW but it came out of a converter app I found on the web and is massively inefficient - 20s of low res AV is over 2 MB! 

     

     


  • RE: Silverlight 2, Databinding to the MediaElement.Position property  

    posted by Gavroche on Jun 24, 2009 18:38
    There is also a performance hit if you use binding to set the position instead of setting the Position property directly. I wrote a test app to prove this as I couldn't (and still can't) understand why this might be! Perhaps someone can shed some light?

    I want to step through a movie - so  I set up a timer to increment the position (each 100ms originally, then each 1s).  The Binding method is a lot slower. Looking at TaskManager the cpu usage with binding looks like a comb  with 100% cpu usage at least half the time. Using property, there are maybe only a few times when the cpu goes 100%, although when it does the pc is still just about locked. I'm playing H264 FWIW but it came out of a converter app I found on the web and is massively inefficient - 20s of low res AV is over 2 MB! 

     

     


Add Comment

 
 

   
  
  
   
Please add 2 and 1 and type the answer here: