10

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

// .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。

感谢你们对我的帮助。

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

4

1 回答 1

1

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

添加:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

viewDidLoad.

更多我的其他帖子

于 2011-11-19T16:24:39.180 回答