Android - Buffering in MediaPlayer

I am using MediaPlayer to play videos in my application. The video takes some time to buffer, and the video for this time is empty.

Is there a way to start buffering when the user is on the previous screen, so when he approaches the video playback screen, is the video ready to play?

Thank you, Chris

+3
source share
4 answers

MediaPlayer allows you to register OnPreparedListener and OnBufferingUpdateListener .

+4
source

, MediaPlayer.prepareAsync(), , .start(), . , ... , , , .

0

as below:

mp.setOnInfoListener(new OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
    if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
        loadingDialog.setVisibility(View.VISIBLE);
    } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
        loadingDialog.setVisibility(View.GONE);
    }
    return false;
}

});

0
source
mediaPlayer.setOnInfoListener(new OnInfoListener() {
    @Override
    public boolean onInfo(MediaPlayer mp, int what, int extra) {
        if (what == 703) {
            // Not documented :(
            // See http://stackoverflow.com/a/9622717/435605
            isBuffering = true;
        } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
            isBuffering = false;
        }
        return false;
    }
});
0
source

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


All Articles