【发布时间】:2011-01-24 18:46:29
【问题描述】:
当没有其他 (iPod) 音乐正在播放时,我需要在我的应用中播放背景音乐。我可以在初始化我的音频会话时确定它:
AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, &varSize, &isPlaying);
但我还想在用户停止 iPod 播放器时播放我的背景音乐(按两次主页按钮并暂停音乐)。我怎样才能捕捉到这个事件?
【问题讨论】:
当没有其他 (iPod) 音乐正在播放时,我需要在我的应用中播放背景音乐。我可以在初始化我的音频会话时确定它:
AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, &varSize, &isPlaying);
但我还想在用户停止 iPod 播放器时播放我的背景音乐(按两次主页按钮并暂停音乐)。我怎样才能捕捉到这个事件?
【问题讨论】:
我找到了:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector (onIPodPlayerPlaybackStateChanged:)
name: MPMusicPlayerControllerPlaybackStateDidChangeNotification
object: [MPMusicPlayerController iPodMusicPlayer]];
[[MPMusicPlayerController iPodMusicPlayer] beginGeneratingPlaybackNotifications];
【讨论】: