Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UITableViewCell iOS中播放视频_Ios_Objective C_Iphone_Tableview - Fatal编程技术网

在UITableViewCell iOS中播放视频

在UITableViewCell iOS中播放视频,ios,objective-c,iphone,tableview,Ios,Objective C,Iphone,Tableview,我想在表格视图单元格中显示和播放视频。我的代码是: 在cellForRowAtIndexPath中: NSURL *videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",path,[[arrAboutUs objectAtIndex:indexPath.row] valueForKey:@"content"]]]; MPMoviePlayerController* moviePlayer = [[MPMovi

我想在表格视图单元格中显示和播放视频。我的代码是: 在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];

但它显示的是空白。我的视频是MP4格式的。

谢谢@milan提出的宝贵建议。我使用avplayervewcontroller,它工作正常。代码:

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

看看这个例子,它很旧,但应该可以与您一起使用。它需要花费大量的时间来播放和显示。我的代码中是否有任何错误。您为什么不使用AVPlayerViewController而不是不推荐的MPMoviePlayerController?@milan因为我对它是新的,所以我刚刚搜索了它,并找到了许多使用MPMoviePlayer的示例。如果您有任何关于AVPlayerViewController的链接或想法,请让我知道。