我想在集合视图单元格中播放视频,要求就像 Instagram 时间线,播放视频就像在 facebook 时间线中播放视频,
为此,我使用了 UICollectionViewCell,我有一些图像,没有视频,现在我是来自画廊的图像,我正在使用相机拍摄图像,并且正在录制视频,每次我都会从上面取出任何一个,然后输出我已添加到时间线。
例如,我们采用 3vc,第一个 vc 具有包含一些图像的集合视图,第二个 vc 我们正在获取输出,它是视频、图像,我将图像和图像的第一帧放入公共数组中,即在 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) receiveArray:(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) receivetitleArray:(NSNotification*)通知
{
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*)通知
{
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;
}
图像和视频第一帧图像添加成功我也想视频,当我滚动时如果索引路径包含任何视频内容,该视频已在单元格中自动播放,在此网址“finalsharevideourl”中我有完整路径
我是目标 c 的新手,请帮助我,感谢您的快速回复