Playing video in UITableViewCell iOS

让人想犯罪 __ 提交于 2020-01-06 05:22:06

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/46237165/playing-video-in-uitableviewcell-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!