android – VideoView触发OnPreparedListener太早HLS

前端之家收集整理的这篇文章主要介绍了android – VideoView触发OnPreparedListener太早HLS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在等待VideoView开始播放HLS时,我想向用户显示一些ProgressDialog.我尝试使用OnPreparedListener,但是他提前触发(播放器下载了m3u8文件后,不是在视频开始时).
VideoView player = (VideoView) findViewById(R.id.player);
String httpLiveUrl = "http://example.com/playlist.m3u8";

player.setVideoURI(Uri.parse(httpLiveUrl));
player.setMediaController(new MediaController(this));
player.requestFocus();

player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
    progress.dismiss();
}
});

progress.show();
player.start();

我没有找到另一个合适的名单…可能是任何人都知道sloution?

解决方法

谢谢大家.我解决了我的问题与下一个黑客:
videoView.setOnPreparedListener(new OnPreparedListener() {
    public void onPrepared(MediaPlayer mp) {

        final Handler handler = new Handler();
        videoPositionThread = new Runnable() {
             public void run() {
                try {
                    int duration = videoView.getCurrentPosition();
                    if (!(videoPosition == duration && videoView.isPlaying())) {
                        progress.dismiss();
                    }
                    videoPosition = duration;
                    handler.postDelayed(videoPositionThread,1000);
                } catch (IllegalArgumentException e) {
                    Log.d(TAG,e.getMessage(),e);
                }
            }
        };
        handler.postDelayed(videoPositionThread,0);
    }
});
原文链接:https://www.f2er.com/android/313766.html

猜你在找的Android相关文章