简体   繁体   English

从网络为AVQueuePlayer / AVPlayer预加载视频文件

[英]Preload video files from network for AVQueuePlayer/AVPlayer

I have a set or URLs, each points to a mp4 video file. 我有一组或者URL,每个都指向一个mp4视频文件。

I have a newsfeed-like timeline for these video files (like Instagram videos). 我对这些视频文件(如Instagram视频)有类似新闻源的时间表。 User can scroll up and down to browse each video. 用户可以上下滚动浏览每个视频。 To make the video-loading faster, I'd like to preload the next few video files before the user scroll down to them. 为了加快视频加载速度,我想在用户向下滚动之前预先加载下几个视频文件。 When the user actually scroll to those files, it will start playing without downloading again from network. 当用户实际滚动到这些文件时,它将开始播放而无需再次从网络下载。

The files will be played in AVQueuePlayer. 这些文件将在AVQueuePlayer中播放。

Is there a way to do this? 有没有办法做到这一点? Thanks guys! 多谢你们!

I don't know of a way to ask AVQueuePlayer to buffer in advance. 我不知道有办法让AVQueuePlayer提前缓冲。

You can create a proxy between AVPlayer and the web. 您可以在AVPlayer和Web之间创建代理。 This will allow you to keep track of what AVPlayer has loaded, so you can predictively download and cache upcoming media files, so they are ready when AVPlayer requests them. 这将允许您跟踪AVPlayer已加载的内容,因此您可以预测性地下载和缓存即将发布的媒体文件,以便在AVPlayer请求它们时准备就绪。 The cleanest way is to register a custom NSURLProtocol (beware that this does not work in the iOS simulator). 最干净的方法是注册自定义NSURLProtocol(请注意,这在iOS模拟器中不起作用)。 You can also run a server on-device such as CocoaHTTPServer. 您还可以在设备上运行服务器,例如CocoaHTTPServer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM