开发者

Setting a kind of callback function to certain seconds of playing video

In android, I am trying to implement an application that can play videos. In this application, I want to fire some callback functions for specific time periods of the video. For example when player plays 30th second of the video, I开发者_如何学JAVA want to call a function f or when 1.30th second is playing function g is called.

How can I implement this functionality? I can start a timer for each function but in this case I have to track playbacks/forwards and modify timer according to these changes.. Do you have any idea?


I've never done this so I can't give much information but just an idea...

Assuming you're going to be using MediaPlayer then you could try extending it for a class of your own.

Within your own class you could maintain a Handler which uses postDelayed(Runnable r, long delayMillis) to trigger some code every 100ms, for example, and have it call the getCurrentPosition() method. You could then have it check the current position against a list of 'trigger points' (30 seconds, 1 min 30 seconds etc) and then perform whatever task necessary.

Doing it this way would mean if the play position is adjusted (using a seek bar, FF/RW etc) you wouldn't need to update a timer - the Runnable would simply continue checking current position without it having to 'know' about any seek changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜