任务完成但出现错误 - 代码:-999 ios 使用 avplayer 播放视频

Posted

技术标签:

【中文标题】任务完成但出现错误 - 代码:-999 ios 使用 avplayer 播放视频【英文标题】:Task finished with error - code: -999 ios playing video with avplayer 【发布时间】:2018-06-19 13:38:48 【问题描述】:

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

- (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 传输:

但我仍然收到此错误:

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

【问题讨论】:

【参考方案1】:

Present 应该在viewDidAppear/viewWillAppear 中加上一个有效的 url

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

【讨论】:

在将代码移动到viewDidAppear 后仍然是相同的错误代码-999,我已经尝试了另一个online source 以确保视频文件正常

以上是关于任务完成但出现错误 - 代码:-999 ios 使用 avplayer 播放视频的主要内容,如果未能解决你的问题,请参考以下文章