iOS – 更新多任务栏中的媒体播放/暂停状态

我们有一个工作的应用程序,使用AUgraphics – CoreAudio API – 播放audio。 graphics总是在运行,并且各种源材料的播放/暂停状态在graphics渲染callback函数中进行pipe理。 我们成功响应了UIEventTypeRemoteControl事件,并且使用MPNowPlayingInfoCenter成功地更新了当前播放内容的元数据的locking屏幕。

一个缺失的部分是更新iOS多任务栏中的播放/暂停button的状态。 它始终处于“暂停”(||)模式,即使应用程序audio已经暂停。 它从不切换到“播放”(>)状态。

哪个API用于更新播放/暂停button状态?

我发现当使用CoreAudio AUgraphics时, AUGraphStart()将在iOS状态栏和iOS多任务栏中显示回放指示符,而AUGraphStop()将清除它们。

更改MPNowPlayingInfo字典,设置新的参数

MPNowPlayingInfoPropertyPlaybackRate to 1.0f to show pause button MPNowPlayingInfoPropertyPlaybackRate to 0.0f to show play button 

从播放button到暂停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; } 

从暂停button到播放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; }