This is on Xcode Version 7.3.1 (7D1014) on OS X 10.11.5 (15F34), target is an iOS application, built for iOS 9.
I have an audio application in which I cannot manage to show the cover art in Now Playing lock screen.
I can show a static image and other information but I'm not able to show the "real" album cover. Code below works correctly (a 512x512 image is displayed:
NSMutableDictionary __block *mpInfo = [[NSMutableDictionary alloc] initWithDictionary:[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo]];
mpInfo[MPMediaItemPropertyArtist] = currentSong.artist;
mpInfo[MPMediaItemPropertyTitle] = currentSong.title;
if([[RP4RadioManager sharedManager] isPlaying]) {
mpInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(1.0);
} else {
mpInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(0.0);
}
mpInfo[MPMediaItemPropertyPlaybackDuration] = @([currentSong.duration doubleValue] / 1000.0);
mpInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(0);
mpInfo[MPMediaItemPropertyArtwork] = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"BigLogo"]];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mpInfo];
some rows below I recover the cover art from the network and I try to show it:
coverImage = [[UIImage alloc] initWithCIImage:currentSong.coverImage];
MPMediaItemArtwork *imageArtwork = [[MPMediaItemArtwork alloc] initWithImage:coverImage];
mpInfo[MPMediaItemPropertyArtwork] = imageArtwork;
DLog(@"Setting cover info. Image: %@, imageArtwork: %@ (%@). mpInfo: %@", coverImage, imageArtwork, NSStringFromCGRect(imageArtwork.bounds), mpInfo);
dispatch_async(dispatch_get_main_queue(), ^{
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mpInfo];
});
The image is valid (usually 500x500px, but this don't seems significant). The image is originally a .jpg, saved in a CIImage (for OS X comaptibility in common code) and then loaded in a UIImage (the same image shows correctly in a UIImageView).
Changing the line
mpInfo[MPMediaItemPropertyArtwork] = imageArtwork;
with
mpInfo[MPMediaItemPropertyArtwork] = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"no_cover"]];
shows a different static image, so the problem is in the original image but I really cannot understand what the problem is... the log line shows an image and a valid MPMeidaItemArtwork
Setting cover info. Image: <UIImage: 0x14eaeed0>, {500, 500}, imageArtwork: <MPMediaItemArtwork: 0x14eaef00> ({{0, 0}, {500, 500}}). mpInfo: {
MPNowPlayingInfoPropertyElapsedPlaybackTime = 0;
MPNowPlayingInfoPropertyPlaybackRate = 1;
albumTitle = "Radio Paradise";
artist = "Other Lives";
artwork = "<MPMediaItemArtwork: 0x14eaef00>";
playbackDuration = "242.8";
title = "Tamer Animals";
}
I suspect it's something really stupid but I don't really know how to debug that.
Any help/hint will be appreciated.