iphonesessionaudioipod

Get notification when iPod music is stopped


I need to play background music in my app when no other (iPod) music is playing. I can determine it when initializing my audio session:

AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, &varSize, &isPlaying);

But I want also to start my background music when user stops iPod player (pressing home button twice and pausing the music). How can I catch this event?


Solution

  • I have found:

    [[NSNotificationCenter defaultCenter] addObserver: self 
        selector: @selector (onIPodPlayerPlaybackStateChanged:)
        name: MPMusicPlayerControllerPlaybackStateDidChangeNotification 
        object: [MPMusicPlayerController iPodMusicPlayer]];
    [[MPMusicPlayerController iPodMusicPlayer] beginGeneratingPlaybackNotifications];