MPMoviePlayerController 未在 iPhone 5 模拟器中触发通知

发布于 2024-12-10 12:39:56 字数 858 浏览 0 评论 0原文

我遇到了一个问题......也许有人遇到了类似的问题:我有一个使用 MPMoviePlayerController 的应用程序,并且曾经工作得很好。 尝试使用 iPhone 5 模拟器使用新的 Xcode 4.2 编译并运行它,当我加载电影时 MPMoviePlayerController 不会发送通知。看起来它无法正确检测视频文件。 代码看起来或多或少像这样(简化的代码):

// First I'm initializing the player with a URL from a file
MPMoviePlayerController *player;
player = [[MPMoviePlayerController alloc] init];
player.shouldAutoplay = NO;
NSURL *url = [NSURL fileURLWithPath:path];
player.contentURL = url;

// Then I'm adding an observer in order to wait for the player to find movie duration
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(durationAvailable:)

在上面之后,我在循环中等待通知被调用,等待大约 10 秒,在此期间我调用运行循环。 使用相同的代码,相同的 Xcode 4.2 版本,但使用 iPhone 4.3 模拟器,大约一秒钟后,通知被调用,我可以读取播放器的持续时间。然而,当在 iPhone 5 模拟器上运行完全相同的代码时,通知函数永远不会被调用,如果我尝试读取电影持续时间,它会包含 0。

有什么想法吗?

谢谢, 爱丽儿

I ran into a problem... perhaps someone bumped into something similar: I have an application that uses a MPMoviePlayerController, and used to work perfectly well.
Trying to compile and run it with new Xcode 4.2 using iPhone 5 Simulator, MPMoviePlayerController is not sending notifications when I load a movie. Looks like it fails to properly detect the video file.
The code looks more or less like that (simplified code):

// First I'm initializing the player with a URL from a file
MPMoviePlayerController *player;
player = [[MPMoviePlayerController alloc] init];
player.shouldAutoplay = NO;
NSURL *url = [NSURL fileURLWithPath:path];
player.contentURL = url;

// Then I'm adding an observer in order to wait for the player to find movie duration
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(durationAvailable:)

After the above, I'm waiting in a loop for the notification to get called, by waiting for about 10 seconds, during which I'm calling the run loop.
Using the same code, same Xcode 4.2 version, but with iPhone 4.3 Simulator, after about a second the notification gets called, and I can read the player duration. However, when running the exact same code on iPhone 5 Simulator, the notification function never gets called, and if I try to read the movie duration afterwards it contains 0.

Any idea?

Thanks,
Ariel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

恋你朝朝暮暮 2024-12-17 12:39:56

好的,我设法找到了解决该问题的方法。
显然,在添加观察者后添加这一行可以解决问题:

[player pause];

看起来如果您不以某种方式“激活”播放器,则不会触发通知。就我而言,我只是想在不开始播放的情况下获得电影播放期间的通知,并且它在 iOS5 之前的版本中运行良好,但看起来他们改变了行为。无论如何,上面的行解决了问题。

爱丽儿

OK, I managed to find a workaround to the problem.
Apparently, adding this line after adding the observer does the trick:

[player pause];

It looks like if you don't "activate" the player somehow, the notifications will not be fired. In my case, I just wanted to get a notification for the duration of the movie without starting a playback, and it worked well in versions prior to iOS5, but it looks like they changed the behavior. Anyway, the above line solves the problem.

Ariel

甜柠檬 2024-12-17 12:39:56

试试这个 MPMoviePlayerPlaybackStateDidChangeNotification :

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(stop)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];

try this MPMoviePlayerPlaybackStateDidChangeNotification :

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(stop)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文