David
David

Reputation: 4895

Add custom album art on lockscreen of iOS devices

I am builting an iOS app that streams shoutcast audio.

I want to display a custom image on the device lockscreen (no matter the song, I want the same image to be displayed).

The code bellow shows me the current title on the lockscreen, but does not display the album art like the image just bellow.

Is possible first (I think, Mixcloud achieves it) ? If yes, what is wrong with this ? Source here.

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
    NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
    UIImage * albumImage = [UIImage imageNamed: @"icon_HD.png"];
    MPMediaItemArtwork * albumArt = [[MPMediaItemArtwork alloc] initWithImage:albumImage];
    [songInfo  setObject:titre.text          forKey:MPMediaItemPropertyTitle];
    [songInfo  setObject:artiste.text        forKey:MPMediaItemPropertyArtist];
    [songInfo  setObject:albumArt            forKey:MPMediaItemPropertyArtwork];
    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}

https://lh6.googleusercontent.com/-yV8VbLatlxg/UoD7Pq-Hv1I/AAAAAAAALVg/UEwKUp00k2U/s1600/iOS-7-lock-screen-music-controls.png

Upvotes: 6

Views: 1954

Answers (1)

Nicolas Vignolo
Nicolas Vignolo

Reputation: 81

This is the code i use on my app. Works fine on iOS7

UIImage *image = [UIImage imageNamed:@"myImage.png"];

MPMediaItemArtwork *albumArtwork = [[MPMediaItemArtwork alloc] initWithImage:image];

NSDictionary *info = @{ MPMediaItemPropertyTitle: @"Song Name",
                        MPMediaItemPropertyArtist: @"Artist Name",
                        MPMediaItemPropertyAlbumTitle: @"Album Name",
                        MPMediaItemPropertyPlaybackDuration: 1.0,
                        MPNowPlayingInfoPropertyElapsedPlaybackTime: 1.0,
                        MPMediaItemPropertyArtwork: albumArtwork };

[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = info;

Let me know if work for you.

Upvotes: 8

Related Questions