VideoView triggers OnPreparedListener too early for HLS

后端 未结 2 894
别那么骄傲
别那么骄傲 2021-02-20 11:09

I want to show user some ProgressDialog while he waits for VideoView to start play HLS. I try to use OnPreparedListener for this, but he triggers to early (after player download

2条回答
  •  别那么骄傲
    2021-02-20 11:45

    Thanks to all. I solved my problem with next hack:

    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);
        }
    });
    

提交回复
热议问题