有谁知道是否有可能检测到VideoView何时缓冲?
我想在视频缓冲时显示ProgressDialog.
到目前为止,我尝试使用OnPreparedListener,但这仅在首次加载视频时才有效.如果正在播放视频并且用户将擦洗条移动到不同的点,则视频仍然"准备好",即使它正在缓冲.
我也试过(我知道这很糟糕)AsyncThread只是忙等待isPlaying():
private class BufferTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void...voids) {
final VideoView videoView = (VideoView)findViewById(R.id.video);
while (!videoView.isPlaying()) { }
return null;
}
protected void onPostExecute(Void v) {
// Hide the dialog here...
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为只要你调用start(),即使它正在缓冲,VideoView似乎也被认为是在播放.
我能想到的唯一解决方案是构建一个自定义的VideoView类型类,以便我可以访问它的MediaPlayer实例.
有任何想法吗?谢谢阅读.