gpt4 book ai didi

android - VideoView 为 HLS 过早触发 OnPreparedListener

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:03 25 4
gpt4 key购买 nike

我想在用户等待 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 吗?

最佳答案

感谢大家。我用下一个 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);
}
});

关于android - VideoView 为 HLS 过早触发 OnPreparedListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13831473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com