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

问题描述 投票:3回答:2

我们有一个使用AU图形的工作应用程序 - CoreAudio API - 来播放音频。图形始终在运行,并且各种源材料的播放/暂停状态在图形渲染回调函数中进行管理。我们成功响应了UIEventTypeRemoteControl事件,并使用MPNowPlayingInfoCenter成功地使用当前播放内容的元数据更新了锁定屏幕。

缺少的一个是更新iOS多任务栏中播放/暂停按钮的状态。它始终处于“暂停”(||)模式,即使应用程序音频已暂停。它永远不会切换到“播放”(>)状态。

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

ios audio core-audio mpnowplayinginfocenter
2个回答
3
投票

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


3
投票

更改MPNowPlayingInfo字典,设置新参数

MPNowPlayingInfoPropertyPlaybackRate to 1.0f to show pause button

MPNowPlayingInfoPropertyPlaybackRate to 0.0f to show 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:1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = songInfo;            
 }

从暂停按钮到播放按钮

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.