简体   繁体   中英

Playing video in UITableViewCell iOS

I want to display and play video in a table view cell. my code for that is: In cellForRowAtIndexPath:

 NSURL *videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",path,[[arrAboutUs objectAtIndex:indexPath.row] valueForKey:@"content"]]];
   MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    [moviePlayer setControlStyle:MPMovieControlStyleNone];
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
    [moviePlayer.view setFrame:cell.frame];
    [cell.contentView addSubview:moviePlayer.view];
    moviePlayer.view.hidden = NO;
    [moviePlayer prepareToPlay];
    [moviePlayer play];

But it is showing blank. and my video is in MP4 formate.

Thank you @milan for your valuable suggestion. I use AVPlayerViewController and it working fine. code for that:

    AVPlayer*player = [[AVPlayer alloc] initWithURL:videoURL];

        AVPlayerViewController* playerController = [[AVPlayerViewController alloc] init];


        playerController.player = player;
       [self addChildViewController:playerController];

        [cell.contentView addSubview: playerController.view];
        playerController.view.frame = cell.frame;

        [player play];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM