Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Audio - Image on Lock Screen

There is a way to add an image to the lock screen for Background Audio, along with setting the Track and Artist name. It was also mentioned in a WWDC 2011 video, but nothing specific to go off of. I have looked everywhere in the docs and cannot find it. I know it is an iOS5 only thing, and Spotify's newest version has this feature. Does anyone know where they can point me in the right direction?

Thank You, Matthew

like image 280
Matthew Knippen Avatar asked Dec 18 '11 20:12

Matthew Knippen


2 Answers

Here's an answer I found for you:

(1) You must handle remote control events. You can't be the Now Playing app unless you do. (See the AudioMixer (MixerHost) sample) code.)

(2) Set the Now Playing info:

MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter]; 
infoCenter.nowPlayingInfo = 
    [NSDictionary dictionaryWithObjectsAndKeys:@"my title", MPMediaItemPropertyTitle,
                                               @"my artist", MPMediaItemPropertyArtist,
                                               nil];

This is independent of whichever API you are using to play audio or video.

like image 146
Michael Dautermann Avatar answered Oct 12 '22 00:10

Michael Dautermann


as per Michaels answer above, simply append

@{MPMediaItemPropertyArtwork: [[MPMediaItemArtwork alloc] initWithImage:[UIImage ...]]}

to the nowPlayingInfo dict

the full options of available keys are ...

// MPMediaItemPropertyAlbumTitle
// MPMediaItemPropertyAlbumTrackCount
// MPMediaItemPropertyAlbumTrackNumber
// MPMediaItemPropertyArtist
// MPMediaItemPropertyArtwork
// MPMediaItemPropertyComposer
// MPMediaItemPropertyDiscCount
// MPMediaItemPropertyDiscNumber
// MPMediaItemPropertyGenre
// MPMediaItemPropertyPersistentID
// MPMediaItemPropertyPlaybackDuration
// MPMediaItemPropertyTitle
like image 28
io2 Avatar answered Oct 12 '22 00:10

io2