iOS 7上的MPNowPlayingInfoCenter AVPlayer

Rém*_*rin 11 ios avplayer avqueueplayer mpnowplayinginfocenter ios7

我正在制作一个可以播放音乐的应用.我正在尝试在锁定屏幕上显示元数据(标题,艺术家和艺术作品图像).

MPNowPlayingInfoCenter似乎很好用MediaPlayer.framework,但我无法想象它可以AVPlayer在iOS 7上运行.

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

AVAudioSession *session = [AVAudioSession sharedInstance];    
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];
Run Code Online (Sandbox Code Playgroud)

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

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

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

    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlaying];
}        
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激 !

谢谢你读这个:)

Rém*_*rin 14

找到了我的问题的答案!

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

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Run Code Online (Sandbox Code Playgroud)