gpt4 book ai didi

crash - MPMusicPlayerController:当 iPod App 在后台终止时,iPod 停止发送通知

转载 作者:技术小花猫 更新时间:2023-10-29 11:08:20 26 4
gpt4 key购买 nike

我正在为 iPod 播放器 Controller 使用音乐播放器属性。

// .h
@property (nonatomic, retain) MPMusicPlayerController *ipodPlayer;

// .m
ipodPlayer = [MPMusicPlayerController iPodMusicPlayer];

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserver:self selector:@selector(changedPlaybackState:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:ipodPlayer];
[notificationCenter addObserver:self selector:@selector(changedNowPlayingItem:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:ipodPlayer];

[ipodPlayer beginGeneratingPlaybackNotifications];

在后台处理期间,如果 iPod 播放器应用程序终止,控制台会打印出:

MediaPlayer: Message playbackState timed out.

如果它没有崩溃(或卡住,降低性能),则通知不再发送到我的观察方法。我仍然可以发送如下消息:

[ipodPlayer pause];
[ipodPlayer play];
[ipodPlayer skipToNextItem];
[ipodPlayer skipToPreviousItem];

但是收不到任何通知

我的问题是:

  1. 有没有办法在运行时重新分配、重新加载指针?如何将属性恢复到刚启动时的状态?
  2. 如何捕捉消息:“MediaPlayer:消息播放状态超时。”在控制台输出中?这不像使用 NSLog。

谢谢你帮助我。

更新:似乎对 ipodPlayer 属性使用 assignweak 是解决方案。此外,访问它是在假设该属性可能不存在的情况下完成的。经过多次试验并在我的应用程序中实际使用它一年后,我认为这是正确的解决方案。

最佳答案

我在 iOS 5 中的 MpMoviePlayerController 也遇到了类似的问题。我找到了解决该问题的修复程序。它也可能在这里工作。

添加:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

viewDidLoad 中。

更多我的其他post

关于crash - MPMusicPlayerController:当 iPod App 在后台终止时,iPod 停止发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com