【问题标题】:How to Play Video from Within Collapsible UITableViewCell?如何从可折叠 UITableViewCell 中播放视频?
【发布时间】:2018-05-16 03:19:35
【问题描述】:

大家好:我已经设置了可折叠的 uitableviewcells,并试图让视频在 didSelectRowAtIndexPath 方法中播放。我可以让单元格向控制台发出打印语句,但无论我试图让视频播放什么都不起作用!代码如下:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if(indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            printf("hello");
        }
        else
        {
        printf("good bye");
        }
    }
    else if(indexPath.section == 1)
    {
        if(indexPath.row == 0)
        {
            printf("hello");
        }
        else
        {
            printf("good bye again");
        }
    }
}

您能告诉我我需要做什么才能播放本地视频文件吗?显然我需要Objective C的帮助!我试图以编程方式创建一个 AVPlayerViewController,然后使用 [self presentviewcontroller] 方法,但我总是收到以下错误(如果我使用 prepareforSegue,这是同样的错误):

  NSString *path = [[NSBundle mainBundle] pathForResource:@"PrelimFig1" ofType:@"m4v"];
        _videoURL = [NSURL fileURLWithPath:path];
        NSLog(@"I want to log: %@", _videoURL);
        AVPlayerViewController *avp = [[AVPlayerViewController alloc]init];
        AVPlayer *player = [AVPlayer playerWithURL:_videoURL];
        avp.player = player;

        [self presentViewController:avp animated:YES completion:nil]
        [player play];

提前感谢您的帮助!

【问题讨论】:

  • 你有什么错误
  • [MediaRemote] [AVOutputContext] 警告:AVF 上下文无法用于 +[MRAVOutputContext sharedAudioPresentationContext]_block_invoke (lldb)

标签: objective-c uitableview avplayer avkit


【解决方案1】:

你可以这样做

   NSURL *videoURLLocal = [[NSBundle mainBundle]URLForResource:@"PrelimFig1" withExtension:@"m4v"];


    AVPlayerViewController *avp = [[AVPlayerViewController alloc]init];
    AVPlayer *player = [AVPlayer playerWithURL:videoURLLocal];
    avp.player = player;
    [self presentViewController:avp animated:YES completion:^{
        [player play];
    }];

       NSURL *videoURLLocal = [[NSBundle mainBundle]URLForResource:@"PrelimFig1" withExtension:@"m4v"];

    // create an AVPlayer
    AVPlayer *player = [AVPlayer playerWithURL:videoURLLocal];

    // create a player view controller
    AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
    controller.player = player;
    [player play];

    // show the view controller
    [self addChildViewController:controller];
    [self.view addSubview:controller.view];
    controller.view.frame = self.view.frame;

【讨论】:

  • 突然间它开始工作了——非常感谢@abdelahad!
  • 像你这样有经验的人花时间帮助我们这些需要帮助的人真是太好了——再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
相关资源
最近更新 更多