升级到 iOS 5 后 MPMoviePlayerController 无法工作
此代码在 iPad 4.3 模拟器上完美运行:
NSString *source = [mediaObject objectForKey:@"source"];
NSString *videoPath = [NSString stringWithFormat:@"%@/%@", path, source];
NSURL *videoUrl = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
videoPlayer.shouldAutoplay = NO;
videoPlayer.view.frame = CGRectMake(xPos, yPos, width, height);
[backgroundImageView addSubview:videoPlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer];
但在 iPad 5 模拟器上不起作用。我得到一个黑框,没有电影或播放控件。
我阅读了有关 MPMoviePlayerController 的 Apple 变更日志,但没有发现任何有关此问题的信息。你能帮助我吗?
This code works perfectly on iPad 4.3 Simulator:
NSString *source = [mediaObject objectForKey:@"source"];
NSString *videoPath = [NSString stringWithFormat:@"%@/%@", path, source];
NSURL *videoUrl = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
videoPlayer.shouldAutoplay = NO;
videoPlayer.view.frame = CGRectMake(xPos, yPos, width, height);
[backgroundImageView addSubview:videoPlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer];
but it doesn't work on iPad 5 Simulator. I get a black frame with no movie nor playback controls.
I read the Apple changelog about MPMoviePlayerController, but I didn't found anything about this problem. Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以这种方式解决了问题:在我的头文件中我写道:
使用此属性:
在我初始化 moviePlayer 的方法中:
似乎将播放器分配给属性“保存”了播放器。但别问我为什么...
I solved the problem in this way: in my header file I wrote:
with this property:
and in the method in which I init the moviePlayer:
It seems that assigning the player to a property "saves" the player. But don't ask me why...
您没有提及您要尝试播放的 URL 类型,但是,如果它是 HTTP Live Streaming 资源(.m3u8 文件),那么请注意,iOS 5.0 似乎加强了对 m3u8 索引文件内容的验证。
具体来说,我发现:
任何单个段的长度都不能超过
#EXT-X-TARGETDURATION
值的两倍;#EXTINF
值(以秒为单位的段长度)现在只能是整数值。如果您的问题是其中之一,则在 iOS 5.0 模拟器下运行您的应用程序应该会在调试器控制台中显示警告。
You don't mention what type of URL you are trying to play, however, if it's an HTTP Live Streaming resource (.m3u8 file), then be aware that iOS 5.0 seems to have tightened up on validating the contents of the m3u8 index file.
Specifically, I've discovered that:
No individual segment can be more than twice as long as the
#EXT-X-TARGETDURATION
value;The
#EXTINF
value (segment length in seconds) can, now, only be an integer value.If one of these is your problem, running your application under the iOS 5.0 simulator should show a warning in the debugger console.
对于 iOS5 上的 HLS,TARGETDURATION 值实际上不是目标持续时间,而是需要是最大持续时间。所以应该设置为文件中最大的段。
For HLS on iOS5, the TARGETDURATION value is really not the target duration but needs to be the maximum duration. So it should be set to the largest segment in the file.