【问题标题】:Retrieving / updating individual MPNowPlayingInfoCenter properties检索/更新单个 MPNowPlayingInfoCenter 属性
【发布时间】:2014-04-28 15:54:03
【问题描述】:

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

我们的AVAudioSessioncategoryactive 状态也是receiving remote control events 也没有问题。

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 打印出一个非常默认的字典,其中仅包含 0 中的 MPNowPlayingInfoPropertyPlaybackRate - 由于在日志期间正在播放音频,因此无论如何这都不准确。

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

【问题讨论】:

    标签: ios avfoundation avplayer mpnowplayinginfocenter


    【解决方案1】:

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

     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;
    

    【讨论】:

    • 感谢@MDB983- 但这与我在上面前 6 行中设置值的方法相同。当您在代码后登录[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo] 时,您会打印出完整的功能集吗?
    • 我可以检查我的代码中的断点,是的,playInfo 显示了许多键/值对。显然这些是您之前设置的值。
    • 这是我刚刚从我拥有的玩家那里获取的日志。信息 { MPNowPlayingInfoPropertyPlaybackRate = 1;艺术家=“科琳·贝利·雷”;艺术品 = "";播放持续时间 = "215.4579591836735"; title = "放上你的记录"; } 所有这些属性之前都在别处设置过。
    • 对 - 不是playInfo,而是实际的defaultCenternowPlayingInfo... 设置值后,我无法访问MPNowPlayingInfoCenter 的值。真奇怪。
    • 这很奇怪,只是将我的 nslog 更改为读取 NSLog("%@", [center nowPlayingInfo]);设置新值后,我将恢复所有新值。
    猜你喜欢
    • 2012-03-20
    • 1970-01-01
    • 2018-09-28
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    相关资源
    最近更新 更多