MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:_itemFailedToPlayToEnd: {kind = 1;new =

MPMoviePlayerViewController或MPMoviePlayerController播放本地视频报错:

_itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
}

在网上搜了很多解决方法都没解决掉。后来发现是url错误。

错误代码:

    NSString *path = [[NSBundle mainBundle] pathForResource: @"test.MOV" ofType: nil];
    
    MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL URLWithString: path]];
    mpvc.moviePlayer.fullscreen = YES;
    mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

正确代码:

    NSString *path = [[NSBundle mainBundle] pathForResource: @"test.MOV" ofType: nil];
    
    MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL: [NSURL fileURLWithPath: path]];
    mpvc.moviePlayer.fullscreen = YES;
    mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

区别仅仅在创建url实例所使用的类方法:

[NSURL URLWithString: path]
生成的URL是:/var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV 

 [NSURL fileURLWithPath: path]
生成的URL是:file:///var/mobile/Applications/3C78D5FF-8953-4AC2-BF5A-293261A5468E/TestVideo.app/test.MOV

看出区别来了吧。

希望对你有所帮助。如果有帮助请回复让我知道。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值