HTTP实时流平滑运行



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

VideoView videoView = (VideoView) findViewById(R.id.videoView);
    String httpLiveUrl = "......";
    videoView.setVideoURI(Uri.parse(httpLiveUrl));
    videoView.setMediaController(new MediaController(this));
    videoView.requestFocus();
    videoView.start();

一旦加载了活动,就会出现黑屏,并在一段时间后运行视频。当我在文档中阅读时,需要在与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方法

hths!

最新更新