我想在collection view cell中播放视频,要求像instagram时间轴播放视频就像在facebook时间轴中播放视频,
为此,我在女巫中使用了 UICollectionViewCell 我有一些图像,没有视频,现在我是图库中的图像,我正在使用相机拍摄图像并录制视频,每次我都会从上面和输出我已经添加到时间线。
例如,我们采用 3vc 第一个 vc 具有一些图像的 Collection View ,第二个 vc 我们得到的输出是视频、图像,我将图像和图像的第一帧放入公共(public)区域来自 VC3 的 VC3 中的数组我正在使用通知中心将数组和输出视频路径 url 传递给 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*)通知 {
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];
} -(无效)sharevideooutputurl:(NSNotification *)通知 {
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;
} 图像和视频第一帧图像添加成功我也想视频,当我滚动时如果索引路径有任何视频contant视频在单元格中自动播放,在这个url“finalsharevideourl”我有完整的路径
我是objective c的新手,请大家帮帮我,感谢您的快速回复
最佳答案
最后我找到了答案,只需更改下面的代码
- (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;
关于ios - 在 Collection View 单元格中播放视频,就像在 Facebook 应用程序时间轴中播放的视频一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848142/