gpt4 book ai didi

带有 MediaController 的 Android VideoView - 如何在流式传输时禁用搜索

转载 作者:行者123 更新时间:2023-11-29 15:55:44 25 4
gpt4 key购买 nike

如果从设备播放视频,媒体播放器知道它的确切长度,并且通过移动媒体 Controller 搜索栏中的拇指快进视频是无缝的。如果从 Internet 播放流媒体视频,则视频长度未知,使用拇指搜索会导致视频停止响应。

我想知道如何在视频完全缓冲之前禁用拇指?然后显示它并启用快进。

以下是我的视频播放器代码:

    setContentView(R.layout.layout_fragment_video_fullscreen);
vvVideoFullscreen = (VideoView) findViewById(R.id.vvVideoFullscreen);
rlVideoFullscreen = (RelativeLayout) findViewById(R.id.rlVideoFullscreen);
videoUri = Uri.parse(video.getUrl());
vvVideoFullscreen.setVideoURI(videoUri);
mediaController = new MediaController(this);
mediaController.setMediaPlayer(vvVideoFullscreen);
mediaController.setAnchorView(vvVideoFullscreen);
vvVideoFullscreen.setMediaController(mediaController);
vvVideoFullscreen.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
rlVideoFullscreen.setVisibility(View.VISIBLE);
vvVideoFullscreen.start();
mediaController.show(3000);
}
});

vVideoFullscreen.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
finish();

}
});

vvVideoFullscreen.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (vvVideoFullscreen.isPlaying()) {

vvVideoFullscreen.pause();
mediaController.hide();

} else {

vvVideoFullscreen.start();
mediaController.show();

}

}
return true;
}

}); // End of setOnTouchListener

最佳答案

您是否尝试过将 onBufferingUpdateListener() 添加到您的 mediaplayer?从文档中说:

public abstract void onBufferingUpdate (MediaPlayer mp, int percent)

Called to update status in buffering a media stream received through progressive HTTP download. The received buffering percentage indicates how much of the content has been buffered or played. For example a buffering update of 80 percent when half the content has already been played indicates that the next 30 percent of the content to play has been buffered.

因此,当以 100% 调用此回调时,您知道您的视频已完全缓冲。

要禁用所有播放控件,您只需在缓冲完成时调用 mediaController.setMediaPlayer(...) 即可。

如果您只想禁用搜索拇指,我建议实现您自己的 MediaController.MediaPlayerControlInterface 并将所有调用路由到您的 MediaPlayer 对象。然后可以通过使 canSeekForward()canSeekBackward() 方法返回 false 并使 seekTo(int pos) 方法关闭来禁用搜索在您的 MediaPlayer 上做任何事情。

关于带有 MediaController 的 Android VideoView - 如何在流式传输时禁用搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28046957/

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