将视频播放到UITableView中 [英] Playing Video into UITableView

查看:86
本文介绍了将视频播放到UITableView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了几篇有关实时流媒体video/audio的帖子.不幸的是,似乎没有任何好的"解决方案.

I have read several posts here about live streaming video/audio. Unfortunately it seems that there is not any "good" solution.

我想为视频提供相同的功能,为图像提供SDWebImageView.

I want same functionality for video which is provided SDWebImageView for images.

现在,我正在使用以下代码:-

Right now, I am using following code:-

NSURL *url=[[NSURL alloc] initWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;

但是当我滚动tableview时,所有视频一次又一次下载.那么,如何我可以停止下载?

But when I scrolled tableview, all videos download again and again. So How can I stop that downloading?

是否有更好的解决方案将视频播放到UITableView中?与 Facebook,Instagram和Vine Apps一样吗?

Is there any better solution for playing video into UITableView? Same Facebook, Instagram, and Vine Apps doing?

推荐答案

不要使用MPMoviePlayerController,请使用AVFoundationAVPlayer.

此外,请勿将您的资产下载与您的UITableViewCell子类耦合.使用其他数据源下载和管理视频资产.

Additionally, don't couple the downloading of your asset to your UITableViewCell subclass. Use an additional data source to download and manage the video assets.

有几种方法可以做到这一点.

There are a few ways you can do this.

  1. 保留由URL初始化的AVPlayerItem对象的数据源数组.不必每次滚动到某个单元时都加载资产,只需将AVPlayerItem加载到单元的播放器中,并在滚动时将其删除.

  1. Keep a data source array of AVPlayerItem objects initialized by URL. Instead of loading the asset each time you scroll to a cell, just load the AVPlayerItem into the cell's player, and remove it when you scroll away.

如果需要保留视频数据,请考虑将每个视频下载到Documents目录中的一个临时文件中.文件下载完成后,使用其initWithURL:方法将该数据加载到AVAsset中,并将URL指向本地文件.准备就绪后,您可以使用initWithAsset:将资产加载到AVPlayerItem并播放视频.

If you need to persist the video data, consider downloading each video to a temporary file in your Documents directory. When the file has finished downloading, load that data into an AVAsset using its initWithURL: method and point the URL to your local file. When ready, you can load your asset into an AVPlayerItem using initWithAsset: and play the video.

这篇关于将视频播放到UITableView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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