Play video in the collection view cell like the videos playing in the Facebook app Timeline

后端 未结 1 988
小鲜肉
小鲜肉 2021-01-22 21:58

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

相关标签:
1条回答
  • 2021-01-22 22:47

    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;
    

    }

    0 讨论(0)
提交回复
热议问题