检索/更新单个MPNowPlayingInfoCenter属性

时间:2014-04-28 15:54:04

标签: ios avfoundation avplayer mpnowplayinginfocenter

在基本音频AVPlayer实例中,我们正在播放HLS流并设置正在播放信息(已成功),但无法访问正在设置的MPNowPlayingInfoCenter的属性。< / p>

我们category的{​​{1}}和active状态以及receiving remote control events也没有问题。

AVAudioSession

NSMutableDictionary *properties = [[NSMutableDictionary alloc] init]; [properties setObject:title forKey:MPMediaItemPropertyTitle]; // Set several other properties MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter]; [center setNowPlayingInfo:properties]; // Works! The lock screen successfully shows the title and other properties NSLog("%@", [center nowPlayingInfo]); 打印一个非常默认的字典,其中只包含NSLog MPNowPlayingInfoPropertyPlaybackRate - 这在日志期间播放音频时无论如何都不准确。

我们希望retrieve the currently-set dictionary of properties,更新一些,然后重新设置它们(适用于专辑封面更新,播放/暂停时间等)。我们缺少什么?

1 个答案:

答案 0 :(得分:0)

尝试以下方法来检索当前属性;

 NSMutableDictionary *playInfo = [NSMutableDictionary dictionaryWithDictionary:[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo] ;

并设置/更新属性如下;

[playInfo setObject:[NSNumber numberWithFloat: 1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
[playInfo setObject:[NSNumber numberWithDouble:songDuration] forKey:MPMediaItemPropertyPlaybackDuration];

[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = playInfo;