3

We have a working app that uses an AU graph - CoreAudio API - to play audio. The graph is always running, and the play/pause state of the various source material is managed in the graph rendering callback functions. We successfully respond to UIEventTypeRemoteControl events, and we successfully update the lock-screen with the meta-data for the currently playing content using MPNowPlayingInfoCenter.

The one missing piece is to update the state of the play/pause button in the iOS multitasking bar. It is always in the "pause" (||) mode, even when the app audio is already paused. It never switches to its "play" (>) state.

Which API is used to update the play/pause button state?

Udi
  • 186
  • 6

2 Answers2

3

I figured out that when using a CoreAudio AU graph, AUGraphStart() will display the playback indicator in the iOS status bar and the iOS multitasking bar, and AUGraphStop() will clear them.

Udi
  • 186
  • 6
3

Change MPNowPlayingInfo dictionary, set new parameter

MPNowPlayingInfoPropertyPlaybackRate to 1.0f to show pause button

MPNowPlayingInfoPropertyPlaybackRate to 0.0f to show play button

From play button - to - pause button

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if(playingInfoCenter) {       
    NSMutableDictionary *songInfo = [NSMutableDictionary dictionaryWithDictionary:[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo];
    //[songInfo setObject:songTitle forKey:MPMediaItemPropertyTitle];
    //[songInfo setObject:songArtist forKey:MPMediaItemPropertyArtist];
    [songInfo setObject:[NSNumber numberWithFloat:1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = songInfo;            
 }

From pause button - to - play button

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if(playingInfoCenter) {         
    NSMutableDictionary *songInfo = [NSMutableDictionary dictionaryWithDictionary:[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo];
    //[songInfo setObject:songTitle forKey:MPMediaItemPropertyTitle];
    //[songInfo setObject:songArtist forKey:MPMediaItemPropertyArtist];
    [songInfo setObject:[NSNumber numberWithFloat:0.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = songInfo;
}
Kuldeep
  • 4,466
  • 8
  • 32
  • 59
Jayesh Lathiya
  • 788
  • 6
  • 18
  • I'm using AVPlayer, and getting same error. And I'm try your solution and it's work in simulator and not working in real device. Please help me out from this problem if u know any other solution. Thanks in advance. – Monika Patel Aug 04 '16 at 11:48
  • This is answer is correct in general, but not with respect to the question. The question is with regards to the core audio API not working properly with MPNowPlayingInfoCenter. – jerry Sep 20 '17 at 22:06