立即调用MPMoviePlayerPlaybackDidFinishNotification [英] MPMoviePlayerPlaybackDidFinishNotification is called immediately

查看:78
本文介绍了立即调用MPMoviePlayerPlaybackDidFinishNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码播放视频:

I'm trying to play video with the following code:

UIGraphicsBeginImageContext(CGSizeMake(1,1));

self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.blablabla.org/app/video/v5_seq8_v2_360p.mp4"]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer];

[self presentMoviePlayerViewControllerAnimated:self.player];

UIGraphicsEndImageContext();

[self.player.moviePlayer prepareToPlay];
[self.player.moviePlayer play];

sel.player关闭并立即调用didFinishPlayback:方法.我从这样的通知中检索错误:

The sel.player closes and didFinishPlayback: method is called instantly. I retrieve the error from the notification like this:

NSLog(@"Error %@", notification.userInfo[@"error"]);

如下所示:

Domain=MediaPlayerErrorDomain Code=-11850 "Operation Stopped"

但是当我在浏览器中打开URL时,视频开始播放,没有任何问题.造成此错误的原因是什么?谢谢

but when i open the url in a browser then the video starts playing without any problems. What can be the cause of this error? Thanks

推荐答案

如果视频在台式机上播放,而不在iOS(应用内或Safari)上播放,则很可能是因为HTTP服务器不支持字节范围请求.如果HTTP服务器不支持字节范围请求,iOS将不会播放视频.这与OS X上的Safari不同,后者无论如何都会播放视频.

If the video plays on your desktop machine, but not iOS (either in-app or in Safari), it's most likely because the HTTP server does not support byte-range requests. If the HTTP server does not support byte-range requests, iOS will not play the video. This differs from Safari on OS X, which plays the video regardless.

来自 Safari Web内容文档:

托管用于iOS的媒体文件的HTTP服务器必须支持字节范围 请求,iOS使用该请求在媒体播放中执行随机访问. (字节范围支持也称为内容范围或部分范围 支持.)大多数(但不是全部)HTTP 1.1服务器已经支持 字节范围请求.

HTTP servers hosting media files for iOS must support byte-range requests, which iOS uses to perform random access in media playback. (Byte-range support is also known as content-range or partial-range support.) Most, but not all, HTTP 1.1 servers already support byte-range requests.

此外,HTTP服务器必须提供有效的Content-Type标头(上面的URL还会枚举有效的MIME类型).如果MIME类型无效或丢失,iOS将不会播放视频.

Also, the HTTP server must provide a valid Content-Type header (the URL above also enumerates the valid MIME types). iOS will not play the video if the MIME type is invalid or missing.

这篇关于立即调用MPMoviePlayerPlaybackDidFinishNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆