在集合视图单元格中播放视频,例如在Facebook应用程序时间轴中播放的视频 [英] Play video in the collection view cell like the videos playing in the Facebook app Timeline

查看:131
本文介绍了在集合视图单元格中播放视频,例如在Facebook应用程序时间轴中播放的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在集合视图单元格中播放视频,要求类似于Instagram时间线,播放视频就像在Facebook时间线上播放视频一样,

I want to play video in the collection view cell,the requirement is like the instagram timeline and playing video is like playing videos in the facebook time line,

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

for this I used UICollectionViewCell in witch I have some images no videos now I am images from gallery,I am taking the image using camera and I am recording the video,every time I will have any one out from the above and the out put i have add to the time line.

例如,我们拿3vc 1st vc有一些图像的集合视图,我第二个vc我们得到输出它是视频,图像,我将图像和图像的第一帧放入VC3中的VC3中的公共阵列我将数组和输出视频路径url传递给1stVC使用通知中心

For example, we take 3vc 1st vc is having collection view with some images,I the second vc we are getting output either it is video,images,I am taking the images and the first frame of the image in to the common array which is in the VC3 from VC3 I am passing the array and the output video path url to the 1stVC using notification center

 - (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我正在检索它们

and In the 1stVC I am retrieving them like this

[[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 *)通知
{

-(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 *)通知
{

-(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 *)通知
{

} -(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;

}
图像和视频第一帧图像正在成功添加我想要视频,当我滚动如果有视频的索引路径在视频中自动播放,则在此网址finalsharevideourl中我有完整路径

} Image and video first frame image is adding successfully I want to video also,when i scroll If the indexpath having any video contant the video have play automatically in the cell, in this url "finalsharevideourl "I have complete path

我是目标c的新手,有些请帮帮我,谢谢快速回复

I am new to the objective c,some please help me out,Thanks for the quick responce

推荐答案

最后我找到了答案,只需更改下面的代码

Finally I found answer for this,just change below code

- (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;

}

这篇关于在集合视图单元格中播放视频,例如在Facebook应用程序时间轴中播放的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆