Add custom album art on lockscreen of iOS devices
Asked Answered
C

1

6

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

Cling answered 27/3, 2014 at 18:37 Comment(6)
Are you titles and artists being changed/set correctly?Ocam
Yes. All those informations are updated correctlyCling
Did you find any solution to this? It used to work correctly on iOS6, but broke on iOS 7... I'm using a similar code and I also experience this issueAlanis
@Alanis : unfortunately noCling
And one year later, any solution to this problem? All other properties work just fine, it's only the Artwork that isn't shown. And yes, the MPMediaItemArtwork that I set can be retrieved from the nowPlayingInfo dictionary and can be seen by with FB chisel visualize (UIImage *)[0x7ffd7a4a8d20 imageWithSize:CGSizeMake(128, 128)] Also is anyone aware of the size the images need to be for lock screen artwork display?Parish
And another year later we don't support iOS 7 anymore. So there.Parish
S
8

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.

Sleep answered 27/8, 2014 at 23:19 Comment(2)
Works as expected for all other properties except Album Art.Parish
I take that back. Works fine for me in iOS 8Parish

© 2022 - 2024 — McMap. All rights reserved.