首页 > 解决方案 > 任务完成但出现错误 - 代码:-999 ios 使用 avplayer 播放视频

问题描述

我想制作一个演示应用程序,只需使用以下示例代码即可播放从网络加载的视频:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:@"http://ftp.cp.108tian.com/video/unity_animation.mov"];
    AVPlayer *avp = [[AVPlayer alloc]initWithURL:url];

    AVPlayerViewController *avpc = [[AVPlayerViewController alloc]init];
    avpc.player = avp;

    [self presentViewController:avpc animated:YES completion:nil];

}

是的,我添加了AST允许 HTTP 传输:

在此处输入图像描述

但我仍然收到此错误:

在此处输入图像描述

发生了什么?以及如何解决这个问题?

标签: iosobjective-cavkit

解决方案


Present应该在viewDidAppear/viewWillAppear除了一个有效的 url

[self presentViewController:avpc animated:YES completion:nil];

推荐阅读