且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android原生视频播放带字幕

更新时间:2022-05-07 17:28:56

在万一有人需要,我做我的解决方案。

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:

  1. 询问媒体播放器的当前秒(有s秒)
  2. 询问媒体播放器的当前秒,直到结果为s + 1(S0)
  3. 获取系统时间(毫秒),该时间(M0)

现在,如果我想在当前电影毫秒:

Now, if I want the current movie milliseconds:

  1. 获取当前系统时间(millisecons)(M1)
  2. 在电影真正的时间是:S0 +(M1-M0)

易,并导致同步字幕;)

Easy, and resulted in synchronized subtitles ;)