在等待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); } });