Adding custom album art to lockscreen iOS devices

I am creating an iOS application that broadcasts shoutcast audio.

I want to display my own image on the device’s locked screen (no matter what song, I want the image to be displayed the same way).

The code below shows the current title on a locked screen, but it does not display the album art as soon as the image below.

Perhaps the first (I think Mixcloud reaches it)? If so, what's wrong with that? The source is 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/AAAAAAAAALVg/UEwKUp00k2U/s1600/iOS-7-lock-screen-music-controls.png

+4
source share
1

, . 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;

, .

+5

Source: https://habr.com/ru/post/1533787/


All Articles