问题 iOS 7上的MPNowPlayingInfoCenter AVPlayer


我正在制作一个流媒体音乐应用。我正在尝试在锁定屏幕上显示元数据(标题,艺术家和艺术作品图像)。

MPNowPlayingInfoCenter 似乎很好用 MediaPlayer.framework,但我无法想让它与之合作 AVPlayer 在iOS 7上。

播放器在后台模式下运行良好 谢谢 AVAudioSession :

AVAudioSession *session = [AVAudioSession sharedInstance];    
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];

这是我在锁屏上显示元数据的代码(这不起作用):

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

if (playingInfoCenter)
{
    NSDictionary *nowPlaying = @{MPMediaItemPropertyArtist: currentTrack.artist,
                                 MPMediaItemPropertyAlbumTitle: currentTrack.title};

    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlaying];
}        

任何帮助,将不胜感激 !

谢谢你读这个:)


9034
2017-12-18 17:49


起源



答案:


找到了我的问题的答案!

使用背景音频时,您必须指定您的应用可以接收远程控制事件:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

14
2017-12-19 10:00



你在哪里放这行代码? - justicepenny
当我开始播放一首歌时。当我不再玩时,我也称这种方法:[[UIApplication sharedApplication] endReceivingRemoteControlEvents]; - Rémy Virin
你确定你使用MPMediaItemArtwork而不是UIImage吗? - Rémy Virin
让我们 在聊天中继续讨论 - Rémy Virin
这个答案对我有帮助。适用于流媒体视频/ HLS直播视频。 - Jonny


答案:


找到了我的问题的答案!

使用背景音频时,您必须指定您的应用可以接收远程控制事件:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

14
2017-12-19 10:00



你在哪里放这行代码? - justicepenny
当我开始播放一首歌时。当我不再玩时,我也称这种方法:[[UIApplication sharedApplication] endReceivingRemoteControlEvents]; - Rémy Virin
你确定你使用MPMediaItemArtwork而不是UIImage吗? - Rémy Virin
让我们 在聊天中继续讨论 - Rémy Virin
这个答案对我有帮助。适用于流媒体视频/ HLS直播视频。 - Jonny