当我没有播放其他(iPod)音乐时,我需要在我的应用中播放背景音乐。我可以在初始化音频会话时确定它:
AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, &varSize, &isPlaying);
但是当用户停止播放iPod播放器(按两次主屏幕按钮并暂停音乐)时,我也想开始播放背景音乐。我怎么能抓住这个事件?
答案 0 :(得分:3)
我找到了:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector (onIPodPlayerPlaybackStateChanged:)
name: MPMusicPlayerControllerPlaybackStateDidChangeNotification
object: [MPMusicPlayerController iPodMusicPlayer]];
[[MPMusicPlayerController iPodMusicPlayer] beginGeneratingPlaybackNotifications];