MPNowPlayingInfoCenter compatible with AVAudioPlayer?

I run -play with AVAudioPlayer and then install the nowPlaying dictionary as follows:

 NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];       MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]]; [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle]; [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist]; [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle]; [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork]; [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; 

The pause button is always displayed on the lock screen. I correctly receive remote control events, and I can switch the play / pause through the events of the remote control, but the lock screen continues to show “pause” even during playback.

Now I have seen this work with MPMoviePlayerController. Can someone explain how MPNowPlayingInfoCenter determines if a play or pause button should be displayed?

+7
ios iphone audio media-player mpnowplayinginfocenter
source share
3 answers

Have you set the correct AVAudioSessionCategory to AudioSession ? It should be AVAudioSessionCategoryPlayback , I believe that it works.

+1
source share

I do not use MPNowPlaying at the moment, but apparently I need to get the information about the sound displayed on the lock screen.

However, in addition to what @ user3061915 said, to control the play / pause button, I used UIEventTypeRemoteControl and works fine for controlling the play / pause button:

 - (void)remoteControlReceivedWithEvent:(UIEvent *)event { //if it is a remote control event handle it correctly if (event.type == UIEventTypeRemoteControl) { if (event.subtype == UIEventSubtypeRemoteControlPlay) { [self playAudio]; } else if (event.subtype == UIEventSubtypeRemoteControlPause) { [self pauseAudio]; } else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) { [self togglePlayPause]; //This method will handle the toggling. } } 
0
source share

I just fixed such a problem in my application. I originally used [[AVAudioSession sharedInstance] setCategory: withOptions: error:] and provided AVAudioSessionCategoryOptionMixWith Other and AVAudioSessionCategoryOptionDuckOthers. This turned out to be my problem. If you establish a connection with others, you do not receive any remote control events. They still go to the iPod app. If you installed other ducks, you get remote control events, but it seems like it causes the problem you are describing: the play / pause button shows the wrong thing. I do not know why. I pressed the play / pause button, setting the option to 0 or actually just calling setCategory: error :.

0
source share

All Articles