Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS的UICollectionView中顺利播放多个视频?_Ios_Objective C_Mpmovieplayercontroller_Avplayer_Alasset - Fatal编程技术网

如何在iOS的UICollectionView中顺利播放多个视频?

如何在iOS的UICollectionView中顺利播放多个视频?,ios,objective-c,mpmovieplayercontroller,avplayer,alasset,Ios,Objective C,Mpmovieplayercontroller,Avplayer,Alasset,我想在我的收藏视图中无限循环播放多个视频 每个视频代表一个单元 我用的是阿拉塞特 我用AVPLayer玩这个游戏,但它不能顺利加载和播放。 任何建议 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [col

我想在我的收藏视图中无限循环播放多个视频

每个视频代表一个单元

我用的是阿拉塞特

我用AVPLayer玩这个游戏,但它不能顺利加载和播放。 任何建议

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
          CGRect attachmentFrame = CGRectMake(2, 2, cell.frame.size.width-4, cell.frame.size.height-4);
           ALAsset *asset = self.assets[indexPath.row];
            UIView* subView;
            if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
                // asset is a video
                avPlayer = [[AVPlayer alloc] initWithURL:[[asset defaultRepresentation] url]];
                avPlayer.muted = YES;
                avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:avPlayer];
                [avPlayerLayer setFrame:CGRectMake(0, 0, cell.frame.size.width-4, cell.frame.size.height-4)];
              subView = [[UIView alloc]initWithFrame:attachmentFrame];
                [subView.layer addSublayer:avPlayerLayer];
                [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
                [cell.contentView addSubview:subView];

                [avPlayer seekToTime:kCMTimeZero];
                avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
                [avPlayer play];

                avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[avPlayer currentItem]];
            }


    }


    - (void)playerItemDidReachEnd:(NSNotification *)notification {
        AVPlayerItem *p = [notification object];
        [p seekToTime:kCMTimeZero];
    }
我还尝试了MPMoviePlayerController,但使用电影播放器,您只能在循环中播放一个视频。与缓冲视频或缩略图相关的任何其他建议。
我不想在视频中播放声音。

AVPlayer
能够在应用程序中非常流畅地播放多个视频,但您需要为采集视图管理单元,因为在您的代码中,当您的单元重新加载时,您的新
AVPlayer
对象将为创建问题的同一视频创建

因此,您需要实现这样一种机制,通过该机制可以实现为一个视频创建单个AVPlayer对象。一个建议是为
AVPlayer
对象管理池


谢谢

我可以管理收藏视图单元格。但是你能给我举一个
AVPlay
的例子吗。谢谢是AVPlay还是AVPlayer?您需要如何使用AVPlayer播放视频的示例代码吗?如果是的话,你可以在谷歌上搜索并轻松找到。比如