Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

ios - Playing Video into UITableView

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

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;

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't use MPMoviePlayerController, use AVFoundation's AVPlayer.

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. 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.

  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...