Reputation: 4895
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];
}
Upvotes: 6
Views: 1954
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