Android Native Video player with subtitles

后端 未结 2 770
旧时难觅i
旧时难觅i 2021-02-06 12:36

I\'m currently developing a video player for android. I\'ve created a simple textview that shows the current subtitle.

The problem is: MediaPlayer getCu

相关标签:
2条回答
  • 2021-02-06 13:22

    1) Parse the subtitle file
    2) Make use of CounterTimer class in set it to player.getDuration() then set an interval of your choice in on tick method (which is called on tick of every interval ) get the current position of your player using player.getCurrentPosition(); (Remember this will return you time in millisecond). Please also remember to store and keep millisecondsLeft.
    3) convert it into your desired format and match it with time hashmap or array you have taken.
    4) Update your TextView which is overlaid on player with the suitable Text.
    5) cancel the Timer for duration period then(you can implement a new Timer with duration time).
    6) After Duration timer finishes in onFinish() you can start the old timer with millisecondLeft time what you saved in STEP 2.

    Thats it ;)

    0 讨论(0)
  • 2021-02-06 13:34

    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.

    Every 20 seconds of video playback I do this procedure:

    1. Ask the mediaplayer for current seconds (got s seconds)
    2. Ask the mediaplayer for current seconds until result is s+1 (s0)
    3. Get the system time (milliseconds) for that time (m0)

    Now, if I want the current movie milliseconds:

    1. Get the current system time (millisecons) (m1)
    2. Movie real time is: s0+(m1-m0)

    Easy, and resulted in synchronized subtitles ;)

    0 讨论(0)
提交回复
热议问题