gpt4 book ai didi

android - Http Live Stream 流畅运行

转载 作者:行者123 更新时间:2023-11-30 01:15:47 26 4
gpt4 key购买 nike

我正在运行在线流,实现示例代码:

VideoView videoView = (VideoView) findViewById(R.id.videoView);
String httpLiveUrl = "......";

videoView.setVideoURI(Uri.parse(httpLiveUrl));
videoView.setMediaController(new MediaController(this));

videoView.requestFocus();
videoView.start();

Activity 一加载,就会出现黑屏,片刻后视频开始运行。正如我在文档中所读到的,它需要在不同于 UI 线程的地方运行。但是,当我添加 run() 时,视频根本没有启动。这里的方法是什么?

最佳答案

我不认为这是一个需要线程的代码问题。

the activity is loaded, a black screen appears and after a while the video is run. 

此观察表明视频播放,但只有在正确缓冲足够的内容后才能开始播放。

您可以做的是通过在当前布局中显示/隐藏您选择的图像并调用 VideoView#setOnPreparedListener 来向应用程序用户指示正在缓冲视频。

这是一个例子:

VideoView videoView = (VideoView) findViewById(R.id.videoView);
String httpLiveUrl = "......";

videoView.setVideoURI(Uri.parse(httpLiveUrl));
videoView.setMediaController(new MediaController(this));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// media file is loaded and ready to go.
hideBufferingUi();
}
});

videoView.requestFocus();
showBufferingUi();
videoView.start();

剩下要实现的就是

  1. 选择一张图片
  2. 将其添加到您的布局中
  3. 添加showBufferingUihideBufferingUi 方法

你好!

关于android - Http Live Stream 流畅运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37883899/

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