Воспроизвести видео в ячейке просмотра коллекции, как видео, воспроизводимое в приложении Facebook.

Я хочу воспроизводить видео в ячейке представления коллекции, требование похоже на шкалу времени Instagram, а воспроизведение видео похоже на воспроизведение видео на шкале времени Facebook,

для этого я использовал UICollectionViewCell, ведь у меня есть некоторые изображения, нет видео, сейчас я являюсь изображениями из галереи, я снимаю изображение с помощью камеры и записываю видео, каждый раз, когда у меня будет кто-то из вышеперечисленных и выходной есть добавить к временной шкале.

Например, мы берем 3vc 1-й vc имеет представление коллекции с некоторыми изображениями, I-ой 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];

-(недействительно) 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;

}

и в коллекции viewcell

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

} Изображение и видео Изображение первого кадра успешно добавляется. Я тоже хочу к видео, когда я прокручиваю. Если в indexpath, имеющем какое-либо видео, видео будет автоматически воспроизводиться в ячейке, в этом URL "финалшаревидеорл" у меня есть полный путь

Я новичок в цели c, некоторые, пожалуйста, помогите мне, спасибо за быстрый ответ

1 ответ

Наконец я нашел ответ на этот вопрос, просто измените код ниже

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

}

Другие вопросы по тегам