我目前正在开发一个视频播放器为Android。我创建了一个简单的TextView,显示当前字幕。
I'm currently developing a video player for android. I've created a simple textview that shows the current subtitle.
的问题是:的MediaPlayer getCurrentPosition()方法只给我时间以秒为单位。我需要以毫秒为单位的值正确同步与电影的字幕。
The problem is: MediaPlayer getCurrentPosition() method only gives me time in seconds. And I need that value in milliseconds to correctly synchronize the subtitle with the movie.
在getCurrentPosition应该给我以毫秒为单位的时间,但它给在几秒钟内* 1000的时间(以000每一个数字结束)。
The getCurrentPosition is supposed to give me the time in milliseconds, but it gives the time in seconds*1000 (every number ends with "000").
你知不知道这样做的更好的办法? 如何获得以毫秒为单位的时间? 在生成事件恰好在第二(000ms)的时间也将正常工作。有什么建议?
在万一有人需要,我做我的解决方案。
In case anyone needs, I did my solution.
我公司开发的字幕模块。 为了得到准确的毫秒,我做了一个同步的系统和播放器的定时器。
I developed the subtitles module. To get the accurate milliseconds, I made a synchronizer for system and player timers.
每20秒的视频播放我做的这个程序:
Every 20 seconds of video playback I do this procedure:
询问媒体播放器的当前秒(有s秒) 询问媒体播放器的当前秒,直到结果为s + 1(S0) 获取系统时间(毫秒),该时间(M0)现在,如果我想在当前电影毫秒:
Now, if I want the current movie milliseconds:
获取当前系统时间(millisecons)(M1) 在电影真正的时间是:S0 +(M1-M0)易,并导致同步字幕;)
Easy, and resulted in synchronized subtitles ;)