I have read several posts here about live streaming video/audio. Unfortunately it seems that there is not any \"good\" solution.
I want same functionali
When you scroll table view then method -tableView:cellForRowAtIndexPath: is fired (actually every time when cell will be visible this method is called). I believe that you are allocating and initializing yours MediaPlayer in this method and that's why video is downloaded again. You could try to add array and store already created cells in it (some kind of cache). Then your -tableView:cellForRowAtIndexPath should check if it has sth cached for actual index. If yes then show cached cell. If no then it should create cell, alloc, and init player and then store cell in cache.
My ViewController has property: NSMutableDictionary *cache; and in ViewDidLoad I have: cache = [[NSMutableDictionary alloc] init];
My -tableView:cellForRowAtIndexPath: looks like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"myCellId";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if ([cache objectForKey:[NSString stringWithFormat:@"key%lu", indexPath.row]] != nil) {
cell = [cache objectForKey:[NSString stringWithFormat:@"key%lu", indexPath.row]];
} else {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:[[NSURL alloc] initWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"]];
[cell addSubview:playerViewController.view];
[cache setValue:cell forKey:[NSString stringWithFormat:@"key%lu", indexPath.row]];
}
return cell;
}
It works for me. Of course you need to use your own datasource etc.