I'm making an app that streams music. I'm trying to display metadata (title, artist and artwork image) on the lock screen.
MPNowPlayingInfoCenter
seems to work well with MediaPlayer.framework
, but I can't figure to make it work with AVPlayer
on iOS 7.
The player is working well in background mode thanks to AVAudioSession
:
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];
Here is my code for displaying metadata on lockscreen (which doesn't work) :
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter)
{
NSDictionary *nowPlaying = @{MPMediaItemPropertyArtist: currentTrack.artist,
MPMediaItemPropertyAlbumTitle: currentTrack.title};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlaying];
}
Any help would be appreciated !
Thanks for reading this :)
Found the answer of my question !
When using background audio, you must specify that your app can received remote control Events :