升级到 iOS 5 后 MPMoviePlayerController 无法工作

发布于 2024-12-10 09:25:24 字数 794 浏览 0 评论 0原文

此代码在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〃安静 2024-12-17 09:25:24

我以这种方式解决了问题:在我的头文件中我写道:

MPMoviePlayerController *moviePlayer;

使用此属性:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

在我初始化 moviePlayer 的方法中:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;

似乎将播放器分配给属性“保存”了播放器。但别问我为什么...

I solved the problem in this way: in my header file I wrote:

MPMoviePlayerController *moviePlayer;

with this property:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

and in the method in which I init the moviePlayer:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;

It seems that assigning the player to a property "saves" the player. But don't ask me why...

入怼 2024-12-17 09:25:24

您没有提及您要尝试播放的 URL 类型,但是,如果它是 HTTP Live Streaming 资源(.m3u8 文件),那么请注意,iOS 5.0 似乎加强了对 m3u8 索引文件内容的验证。

具体来说,我发现:

  1. 任何单个段的长度都不能超过 #EXT-X-TARGETDURATION 值的两倍;

  2. #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:

  1. No individual segment can be more than twice as long as the #EXT-X-TARGETDURATION value;

  2. 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.

多像笑话 2024-12-17 09:25:24

对于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文