Search code examples
delphidelphi-xe2livebindings

Syncronizing TMediaPlayer.Position and TTrackBar.Position via LiveBindings


I have a TTrackBar and a TMediaPlayer, I'm looking for a way to change the TTrackBar position according to the TMediaPlayer position using the LiveBindigs feature.

The problem is, there is no event on the TMediaPlayer to watch the changes of the TMediaPlayer.Position property, so my TTrackBar.Position can't synchronize.

Is it possible to watch the changes of a component property without trigger an event?


Solution

  • Not it is not possible to monitor changes of certain property without suitable event.

    And you would not want to have any event binded to MediaPlayer.Position property either. Why?

    For instance when you are playing a video position is changed for each and every frame which menans that when playing a video with 30 FPS such event would be fired 30 times per second. So depending on the code in that event it could quickly bring your application to a crawl.

    So best suggestion that I can give you is for you to place a timer on your form and then check media player position in certain intervals to update your TrackBar. I believe one second interval would is more than enough but you can make it shorter if you will.

    Just make sure that if you also use TrackBar for seeking ability to use some control variable to see whether the TrackBar position is being updated by user or by your Timer. Other vise you will end up with weird stuttering (happened to me the first time).

    As for achieving all this with LiveBindings alone I don't think it is possible.