11

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

Rémy Virin
  • 3,213
  • 20
  • 40

1 Answers1

14

Found the answer of my question !

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

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Rémy Virin
  • 3,213
  • 20
  • 40
  • When I start playing a song. I call this method too, when I'm not playing anymore : [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; – Rémy Virin Mar 10 '14 at 17:20
  • thanks for your reply. actually still no luck, I use the https://github.com/mattgallagher/AudioStreamer , to stream the radio. I wanna show the radio station picture on the lock screen, every data are there. just not show on lock screen :( – justicepenny Mar 10 '14 at 17:31
  • what i mean is every data is there meaning I got all the information that i need and fill it in dictionary .. but on lock screen has no control there , no album title, no image there . and i do put this, but this no luck [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlaying]; – justicepenny Mar 11 '14 at 09:19
  • Did you check "Audio and Airplay", under "background modes" ? it's in your project settings under "capabilities". – Rémy Virin Mar 11 '14 at 09:39
  • you mean in infoplist? "Required background modes" i have set it – justicepenny Mar 11 '14 at 09:46
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49462/discussion-between-remy-virin-and-justicepenny) – Rémy Virin Mar 11 '14 at 09:48
  • Hello @RémyVirin have you been able to solve your issue... i am also struck on same issue can you pls help me? – Rohit Nov 19 '14 at 11:23
  • @Rohit, yes but how ?Have you tried what I suggest ? – Rémy Virin Nov 19 '14 at 14:45
  • @RémyVirin i have tried it and magically i got it working for iOS 8 that too for downloaded files not for files streaming from server. I could not understand where i am going wrong have search many other answers also but could only got it working for iOS 8 (downloaded files only). Thanks for help.. – Rohit Nov 20 '14 at 06:44
  • 1
    This answer helped me. Works for streaming video / HLS live video. – Jonny Aug 24 '17 at 06:26