我想和fitStar App同时播放多个视频(使用Scrollview或者带有分页的CollectionView),但滚动时不顺畅,并在一段时间后给出内存警告...请建议
先谢谢
答案 0 :(得分:1)
AVPlayer 能够非常流畅地在应用中播放多个视频,但您需要管理收藏视图的单元格。还有一个建议是管理AVPlayer 对象的池,而不是创建单个对象。
答案 1 :(得分:0)
您可以使用AVPlayer Simply使用此代码,它可以正常使用
//Change the return value how many video screen you want
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
myCell *cell = [myTable dequeueReusableCellWithIdentifier:@"cell"];
//You can set multiple video path using array
NSString *filePath = [[NSBundle mainBundle] pathForResource:@“myVideo” ofType:@"MOV"];
NSURL *url = [NSURL fileURLWithPath:filePath];
cell.videoPlayer = [[AVPlayer alloc]init];
cell.avLayer = [[AVPlayerLayer alloc]init];
NSLog(@"url %@",url);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
dispatch_sync(dispatch_get_main_queue(), ^{
cell.videoPlayer = [AVPlayer playerWithURL:url];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = cell.videoPlayer;
[cell.videoPlayer play];
// show the view controller
[self addChildViewController:controller];
[cell.myView addSubview:controller.view];
controller.view.frame = cell.myView.frame;
});
});
return cell;
}