在VideoView Android中停止自动缓冲 [英] Stop auto buffer in VideoView android

查看:190
本文介绍了在VideoView Android中停止自动缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施视频下载器应用.用户可以在下载视频之前先观看视频.但是问题是,当activity启动时,视频会开始自动缓冲,这会浪费用户的更多互联网数据.我已经为videoview提供了下载button,因此用户可以根据需要观看视频,然后下载.由于具有自动缓冲功能,因此用户需要两倍于视频的数据.

一旦活动/视频观看成为焦点,是否有任何方法可以停止自动缓冲视频. 我的问题的全部是保存用户数据.

视频观看代码:

 var videoView = FindViewById<VideoView>(Resource.Id.videoView1);
        var uri = Android.Net.Uri.Parse(url);
        videoView.SetVideoURI(uri);
        videoView.SeekTo(100);
        MediaController mediaController = new
        MediaController(this);
        mediaController.SetAnchorView(videoView);
        videoView.SetMediaController(mediaController);

3年前有人问这个问题,但没人回答. VideoView中的控件缓冲

任何帮助将不胜感激. TIA !!!

解决方案

VideoView使用 ExoPlayer . ExoPlayer是一个开源库,可让您更好地控制媒体缓冲和播放.它得到了Google在其文档中的认可,并且开发人员实际上出现在Google I/O事件中,并进行了有关该项目的会议.

ExoPlayer具有一个名为 LoadControl ,用于控制媒体的缓冲.您可以尝试使用 DefaultLoadControl 实施或自行部署.

这是一个教程和一个演示应用.

我知道还有其他方法可以实现您的目标,但是我怀疑您是否想通过完全实现自己的缓冲机制来冒险该项目.

I am implementing Video Downloader App. In which user can view video before downloading it.But problem is that when activity starts video starts auto buffering, which waste more internet data of user. I have provided videoview with download button so user can view video if he want's and then download. Because of auto buffer user needs twice the data for video.

Is there any way to stop auto buffer video as soon as activity/videoview comes in focus. All point of my question is to conserve user data.

Videoview code :

 var videoView = FindViewById<VideoView>(Resource.Id.videoView1);
        var uri = Android.Net.Uri.Parse(url);
        videoView.SetVideoURI(uri);
        videoView.SeekTo(100);
        MediaController mediaController = new
        MediaController(this);
        mediaController.SetAnchorView(videoView);
        videoView.SetMediaController(mediaController);

Btw someone asked this question 3 years ago no one answered it yet. Control buffering in VideoView

Any help be appreciated. TIA !!!

解决方案

VideoView uses the MediaPlayer class internally and doesn't give you any control over starting or stopping the buffering. In fact, buffering of the video starts when PrepareAsync is called in the MediaPlayer class.

Now, when we look at your code, there's a call to SetVideoUri method. Internally that method calls a private openVideo method which prepares the MediaPlayer instance and calls prepareAsync which starts the buffering. If you are really interested in the internal implementation, you can take a look at the C++ source here. The takeaway from all this is that you won't be able to stop buffering taking place if you use the VideoView.

Solution: Use ExoPlayer. ExoPlayer is an open source library that gives you a better control over media buffering and playback. It's endorsed by Google in their documentation and the developer actually appeared in Google I/O event with a session about the project.

ExoPlayer has an interface called LoadControl which is used for controlling the buffering of media. You could try to use the DefaultLoadControl implementation or roll out your own.

Here's a tutorial and a demo app on how to get started with the library.

I know there are other ways to achieve your goal but I doubt you want to risk the project by fully implementing your own buffering mechanism.

这篇关于在VideoView Android中停止自动缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆