为什么 MPMoviePlayerController 在模拟器中有效,但在设备中无效?
我无法让 MPMoviePlayerController 在设备上运行。它在模拟器中运行良好,播放五秒视频,然后将适当的回调 (myMovieFinishedCallback:
) 发送到视图控制器。当它在设备上运行时,电影永远不会显示,即使我可以毫无问题地通过 [player play]
进行跟踪。 myMovieFinishedCallback:
从未被调用,并且没有错误。所有正确的资源都被复制。知道发生了什么事吗?
这是我用来创建和使用播放器的代码,
更新:我已改用 MPMoviePlayerViewController。在设备上,电影仍然无法播放,我只是无限期地旋转进度轮。即使我将播放器设置为 MPMovieControlStyleNone,控件也会短暂闪烁 - 有人知道我该如何解决这个问题吗?影片时长 5 秒,大小约为 1.5 MB(如果有什么不同的话)。
更新:其他电影文件可以工作,但我不知道如何让我的文件工作。我已经尝试过将其作为 .mov 和 .mp4 进行使用,设置似乎是正确的。知道什么会导致 MPMoviePlayer 仅在设备上永远显示进度轮吗?
- (void) playMovie
{
NSString *url = [[NSBundle mainBundle]
pathForResource:@"myMovie"
ofType:@"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
playerViewController.view.frame = movieView.frame;
[movieView addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
I'm having trouble getting MPMoviePlayerController to work on the device. It runs fine in simulator, playing a five-second video and then sending the appropriate callback (myMovieFinishedCallback:
) to the view controller. When it runs on the device, the movie never shows up, even though I can trace through [player play]
with no problems. myMovieFinishedCallback:
is never called, and there are no errors. All the right resources are being copied. Any idea what's going on?
Here's the code I use to create and use the player,
Update: I've switched over to using MPMoviePlayerViewController. On the device the movie still does not play, I just get the spinning progress wheel indefinitely. The controls also flash briefly even though I've set the player to MPMovieControlStyleNone - anybody know how I can fix this? The movie is five seconds and about 1.5 MB if that makes any difference.
Update: Other movie files work, but I can't figure out how to make mine work. I've tried it as a .mov and a .mp4 and the settings seem to be right. Any idea what would cause the MPMoviePlayer to show a progress wheel forever on the device only?
- (void) playMovie
{
NSString *url = [[NSBundle mainBundle]
pathForResource:@"myMovie"
ofType:@"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
playerViewController.view.frame = movieView.frame;
[movieView addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码对我来说工作得很好,因此我想到了两种可能性(可能还有其他可能性):
我会尝试使用不同的视频。也许您可以确认您之前曾在该设备上玩过游戏。这是我整理的小演示项目:http://www.cimgf.com/files/PlayMovie。邮编
Your code works fine for me, so there are two possibilities that come to mind (there may be others):
I would try using a different video. Maybe one you can confirm you've played on the device before. Here's the little demo project I threw together: http://www.cimgf.com/files/PlayMovie.zip