How to get a callback for every second player you play in Android players

I am using an Android media player to play videos in my application. I want to show a button to skip a video after 5 seconds of actual playback. First I show "Skip video in 5 seconds." Then, when the player continues to play the video, he will continue to update the button text with “Skip video in 4 s”, etc. Every second. Finally, it will show "Skip Video".

I do not know how to get a callback in every second. Because I do not update the button text when the player buffers or the player pauses.

So far I have tried:

public void onBufferingUpdate(MediaPlayer mp, int percent) {
    // TODO Auto-generated method stub
    updateSkipButtonUI();

}

But since I tested some devices, the onBufferingUpdate method is called every second when the player plays the video. But on some devices, it is not called as soon as the percentage of buffering reaches 100%.

I also tried

mMediaPlayer.setOnInfoListener(this);
    @Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
    // TODO Auto-generated method stub
    if(what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
    {
        //Player started buffering. Player internally pauses . 
        stopTimerToUpdateSkipButton();
    }
    else if(what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
    {
        // Buffering has ended . Content is ready to play.
        startTimerToUpdateSkipButton();
    }

    return what == MediaPlayer.MEDIA_INFO_BUFFERING_START || what == MediaPlayer.MEDIA_INFO_BUFFERING_END;
}

But the OnInfo method is also sometimes called. Sometimes it is not called.

I do not know what else to try. Please help.

+4
source share

Source: https://habr.com/ru/post/1648488/


All Articles