Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPNowPlayingInfoCenter AVPlayer on iOS 7

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 :)

like image 355
Rémy Virin Avatar asked Dec 18 '13 17:12

Rémy Virin


1 Answers

Found the answer of my question !

When using background audio, you must specify that your app can received remote control Events :

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
like image 153
Rémy Virin Avatar answered Nov 11 '22 03:11

Rémy Virin