3

I have an online audio player app. I want the user to have controls of the app's play and pause even from the locked screen. The buttons are already shown by default. The code for my app is here.

Now how to enable the buttons to control my player. And how to show the image of my App when the screen of the App is locked. This is the example image

enter image description here

Please help if this is possible. Thanx in Advance.

Community
  • 1
  • 1
ZooZ
  • 309
  • 5
  • 19

1 Answers1

4

iOS 5 onwards, MPNowPlayingInfoCenter supports the setting of the track title as well as album art image in both the lock screen and the remote playback controls.
To check whether MPNowPlayingInfoCenter is available, try this:-

if ([MPNowPlayingInfoCenter class])  {
   UIImage *albumArtImg = [UIImage imageNamed:@"abc.png"];
   albumArt = [[MPMediaItemArtwork alloc] initWithImage:albumArtImg];

    NSDictionary *dictCurrentlyPlaying = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Temporary", [NSNumber numberWithInt:22], albumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle, MPMediaItemPropertyPlaybackDuration, MPMediaItemPropertyArtwork, nil]];
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = dictCurrentlyPlaying;
}

Updated:-
Please have a look at these:-
1. http://jaysonlane.net/tech-blog/2012/04/lock-screen-now-playing-with-mpnowplayinginfocenter/
2. How to set the title when playing music in background on iPhone?

Community
  • 1
  • 1
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39