Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMusicPlayerController: iPod stops sending notifications, when iPod App is terminated in background

I am using a music player property for iPod player controller.

// .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];

During background processing, if iPod player app is terminated, the console prints out:

MediaPlayer: Message playbackState timed out.

If it doesn't crash(or freezes, slowing performance), the notification is not being sent to my observing methods anymore. I can still send messages like:

[ipodPlayer pause];
[ipodPlayer play];
[ipodPlayer skipToNextItem];
[ipodPlayer skipToPreviousItem];

but can't receive any notifications

My questions are:

  1. Is there are way to reassign, reload pointers during runtime? How can I restore the property to be just like when it's first launched?
  2. How can I catch the messge:"MediaPlayer: Message playbackState timed out." in console output? This is not like using NSLog.

Thank you for helping me.

UPDATED: It seems like using assign or weak for ipodPlayer property was the solution. Also, accessing it is done with assumption that the property may not be there. After many trials and a year of actually using it in my app, I think this was the right solution.

like image 405
petershine Avatar asked Aug 21 '10 19:08

petershine


1 Answers

I had similar issue with my MpMoviePlayerController in iOS 5. I Found a fix that took care of it. It might work here as well.

Add:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in viewDidLoad.

More my other post

like image 64
rydgaze Avatar answered Nov 15 '22 23:11

rydgaze