在collections视图单元中播放video,例如在Facebook应用时间轴中播放的video

我想在collections视图单元格中播放video,需求就像instagram时间线,播放video就像在Facebook时间线上播放video一样,

为此我使用了UICollectionViewCell巫婆我现在有一些图像没有video我是从画廊的图像,我正在使用相机拍摄的图像,我正在录制的video,每次我会有任何一个从上面出来,把我有添加到时间线。

例如,我们采取3vc第一个vc是有一些图像收集视图,我第二个vc我们得到的输出要么是video,图像,我正在把图像和图像的第一帧中的共同数组是在从VC3的VC3中,我将数组和输出videopathurl传递给使用通知中心的1stVC

- (IBAction)sharebuttn:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ // Tabbar index [[NSNotificationCenter defaultCenter] postNotificationName:@"ShareArray" object:_selectedimgarray]; [[NSNotificationCenter defaultCenter] postNotificationName:@"SharetitleArray" object:_newtile]; [[NSNotificationCenter defaultCenter] postNotificationName:@"sharevideooutputurl" object:_finalvideourl]; }]; 

在1stVC中,我正在像这样检索它们

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedArray:) name:@"ShareArray" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedtitleArray:) name:@"SharetitleArray" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sharevideooutputurl:) name:@"Sharevideourl" object:nil]; 

– (void)receivedArray 🙁 NSNotification *)notification {

  NSMutableArray* userInfo = notification.object; UIImage *image = [userInfo firstObject]; if ([userInfo count]>0) { //[_imagearray insertObject:[userInfo firstObject] atIndex:0]; [app.array1 insertObject:[userInfo firstObject] atIndex:0]; [self.collection reloadData]; NSLog(@"%@",app.array1); } //[_imagearray insertObject:[userInfo firstObject] atIndex:0]; // [self.collection reloadData]; _collection.delegate=self; _collection.dataSource=self; 

}

– (void)receivedtitleArray 🙁 NSNotification *)notification {

  NSMutableArray* userInfotitle = notification.object; NSLog(@"%@",userInfotitle); //[_tittlearray insertObject:[userInfotitle firstObject] atIndex:0]; [app.tarray1 insertObject:[userInfotitle firstObject] atIndex:0]; NSLog(@"%@",app.tarray1); //NSLog(@"%@",_tittlearray); _collection.delegate=self; _collection.dataSource=self; [self.tabBarController setSelectedIndex:0]; //[self.collection reloadData]; 

} – (void)sharevideooutputurl:(NSNotification *)notification {

 NSURL *finalsharevideourl=notification.object; [self.collection reloadData]; _collection.delegate=self; _collection.dataSource=self; 

}

并在集合视单元中

  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { //[self.collection reloadData]; homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; UIImage *image; NSInteger row = [indexPath row]; NSLog(@"indexpath = %ld", (long)row); if( [app.array1[row] isKindOfClass:[UIImage class]]) { image= app.array1[row]; } else { image = [UIImage imageNamed:app.array1[row]]; } cell.img.image = image; cell.text.text=[app.tarray1 objectAtIndex:indexPath.row]; return cell; 

}图像和video第一帧图像添加成功我也想要video,当我滚动如果有任何video的索引pathvideo有自动播放单元格中,在这个URL“finalsharevideourl”我有完整的path

我是新来的目标C,有些请帮助我,感谢您的快速回应

最后我find了答案,只是改变下面的代码

 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { //[self.collection reloadData]; homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; UIImage *image; NSInteger row = [indexPath row]; NSURL *furl; NSLog(@"indexpath = %ld", (long)row); if ([app.array1[row] isKindOfClass:[NSURL class]]) { furl=app.array1[row]; cell.movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:app.array1[row]]; cell.videoview.hidden=NO; cell.img.hidden=YES; cell.movieplayer.view.frame = cell.img.frame; [cell.videoview addSubview:cell.movieplayer.view]; NSLog(@"%@",cell.movieplayer); [cell.movieplayer play]; NSLog(@"%@",cell.movieplayer); } else { if ([app.array1[row] isKindOfClass:[UIImage class]]) { image= app.array1[row]; cell.img.hidden=NO; cell.videoview.hidden=YES; } else { image = [UIImage imageNamed:app.array1[row]]; cell.videoview.hidden=YES; cell.img.hidden=NO; } cell.img.image = image; } cell.text.text=[app.tarray1 objectAtIndex:indexPath.row]; return cell; 

}