Android Native Video Player with subtitles

I am currently developing a video player for Android. I created a simple text view that shows the current subtitle.

The problem is this: MediaPlayer getCurrentPosition () method gives me time in seconds. And I need this value in milliseconds to correctly synchronize the subtitles with the movie.

GetCurrentPosition is supposed to give me time in milliseconds, but gives me time in seconds * 1000 (each number ends with "000").

  • Do you know the best way to do this?
  • How to get time in milliseconds?
  • An event creation will also be created exactly during the second (000ms).

Any suggestions?

+5
source share
2 answers

If necessary, I made my decision.

I developed a subtitle module. To get the exact milliseconds, I made a synchronizer for the system timers and players.

Every 20 seconds of video playback, I perform this procedure:

  • Request media player for current seconds (seconds received)
  • Request a media player for the current seconds until the result is s + 1 (s0)
  • Get system time (milliseconds) in that time (m0)

Now, if I want the current millisecond of the movie:

  • Get current system time (milliseconds) (m1)
  • Current video: s0 + (m1-m0)

Easy and led to synchronized subtitles;)

+3
source

1)
2) CounterTimer, player.getDuration(), tick ( ), , player.getCurrentPosition(); (, ). . 3) hashmap , .
4) TextView, .
5) ( ).
6) , onFinish(), , STEP 2.

Thats it;)

0

All Articles