如何缓存AVPlayerItem(视频)以便在UITableview中重用 [英] How to cache an AVPlayerItem (Video) for reuse in a UITableview

查看:146
本文介绍了如何缓存AVPlayerItem(视频)以便在UITableview中重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableView中显示了许多视频。视频远程存储在服务器上。我可以使用以下一些代码将视频加载到tableview中。

I have a number of videos that I am displaying in a UITableView. The videos are stored remotely on a server. I am able to load the videos into the tableview using some of the following code.

 NSString *urlString = [NSString stringWithFormat:[row objectForKey:@"video_uri"]];
 NSURL* url = [NSURL URLWithString:urlString];
 AVPlayerItem *pItem = [AVPlayerItem playerItemWithURL:url];
 AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];

每次tableview使单元格出列,然后再次重新排队,再次从网址加载视频。我想知道是否有办法下载和缓存或保存视频,以便可以从手机播放,而无需再次连接。我试图绘制使用 LazyTableImages

Each time the tableview dequeues the cell then requeues again the video is loaded again from the url. I'm wondering if there is a way to download and cache or save the video so that it can be played from the phone without having to connect again. I was trying to draw opoin the technique used in the LazyTableImages example provided by Apple, but I'me a little stuck.

推荐答案

在搞乱这个尝试缓存AVPlayerItems失败之后,我得出的结论是,如果你缓存AVPlayerItem的底层AVAsset并且意图重用它会更好,而AVPlayerItem本身并不意味着可以重用。

After messing around with this unsuccessfully trying to cache AVPlayerItems, I've come to theh conclusion that it works much better if you cache the AVPlayerItem's underlying AVAsset which is meant to be reused, whereas the AVPlayerItem itself is not meant to be reused.

这篇关于如何缓存AVPlayerItem(视频)以便在UITableview中重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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