I made some changes to allow for notifications and to use the ipodMusicPlayer instead of applicationMusicPlayer as below. This works OK as long as I stay in this scene. The problem is that when I go to another scene, when I come back to this scene it crashes with an error as shown below the code here. Any help would be greatly appreciated.
In my main scene, this works OK and I can use play , pause, next or previous song and all works OK.
// instantiate a music player
NSLog(@"Start iPod player");
// myPlayer = [MPMusicPlayerController applicationMusicPlayer];
//
myPlayer = [MPMusicPlayerController iPodMusicPlayer];
//
// assign a playback queue containing all media items on the device
//[myPlayer setQueueWithQuery: [MPMediaQuery songsQuery]];
[myPlayer setQueueWithQuery: [MPMediaQuery playlistsQuery]];
//
NSLog(@"Register for iPod player notifications");
// Register for music player notifications
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(Songtitleshow)
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
object:myPlayer];
[notificationCenter addObserver:self
selector:@selector(handlePlaybackStateChanged)
name:MPMusicPlayerControllerPlaybackStateDidChangeNotification
object:myPlayer];
//
[myPlayer beginGeneratingPlaybackNotifications];
//
//
//
NSLog(@"Generate notifications started");
but when I go to another scene with the code below, the help scene loads OK and works fine, but when I come back to my main scene and use play, pause, next or previous song controls on the player, it crashes my app.
-(void)help: (id)sender
{
NSLog(@"Start going to settings page");
//
// load the settings menu
SettingsScene * sts = [SettingsScene node];
[[CCDirector sharedDirector] replaceScene:sts]; //
return;
}
Console shows this :
Start iPod player ( app started here )
Register for iPod player notifications
Generate notifications started
Start show song artist/title
User is playing the following song: Highway To Hell
User is playing the following artist: AC/DC
End show song artist/title
Start playback status notification
CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: 0.10 to 1.00
Start show song artist/title
User is playing the following song: Hells Bells
User is playing the following artist: AC/DC
End show song artist/title
Start playback status notification
Start Track up main
End Track up main
CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: 0.10 to 1.00
Start show song artist/title
User is playing the following song: Back In Black
User is playing the following artist: AC/DC
End show song artist/title
Start going to settings page ( here's where I go to the help scene )
Start iPod player ( here's where I come back from the help scene )
Register for iPod player notifications
Generate notifications started
Start show song artist/title
User is playing the following song: Back In Black
User is playing the following artist: AC/DC
End show song artist/title
Start playback status notification
Start Track up main
End Track up main
CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: 0.10 to 1.00
Program received signal: “EXC_BAD_ACCESS”.
So right after I use track up, the app crashes. It does go to the next song and play, but my app crashes. So I think maybe it's something to do with the notifications selector, I just can't figure out what it is.