为什么 MPMoviePlayerController 在模拟器中有效,但在设备中无效?

发布于 2024-09-14 02:59:47 字数 1435 浏览 3 评论 0原文

我无法让 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 技术交流群。

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

发布评论

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

评论(1

一口甜 2024-09-21 02:59:47

您的代码对我来说工作得很好,因此我想到了两种可能性(可能还有其他可能性):

  1. 您的movieView尚未正确初始化或尚未将其框架设置为可见。
  2. 该设备不支持您正在显示的视频的视频格式。

我会尝试使用不同的视频。也许您可以确认您之前曾在该设备上玩过游戏。这是我整理的小演示项目: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):

  1. You movieView has not been properly initialized or has not had its frame set so that it's visible.
  2. The video format of the video you're displaying isn't supported on the device.

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

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