I'm tweaking a forked TouchBar application which shows widgets on the Mac TouchBar, and am trying to get album art to display on the NowPlaying Widget. This is the project.
Currently, I'm having issues with this piece of code:
- (void)updateInfo
{
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(),
^(NSDictionary *info)
{
NSString *album = [info objectForKey:kMRMediaRemoteNowPlayingInfoAlbum];
NSString *artist = [info objectForKey:kMRMediaRemoteNowPlayingInfoArtist];
NSString *title = [info objectForKey:kMRMediaRemoteNowPlayingInfoTitle];
NSData *artworkData = [info objectForKey:kMRMediaRemoteNowPlayingInfoArtworkData];
NSImage *albumart = nil;
if (nil != artworkData && ![artworkData isEqual:[NSNull null]])
{
albumart = [[NSImage alloc] initWithData:artworkData];
}
if (nil != albumart)
{
self.appIcon = albumart;
}
if (self.album != album || self.artist != artist || self.title != title || self.albumArt != albumart)
{
self.album = album;
self.artist = artist;
self.title = title;
self.albumArt = albumart;
[[NSNotificationCenter defaultCenter]
postNotificationName:NowPlayingInfoNotification
object:self];
}
});
}
The main issue I'm running into is that the album art data only shows up for about half a second after the song starts, afterwards, it disappears. My theory is that kMRMediaRemoteNowPlayingInfoArtworkData is the wrong thing to use to get artwork data, but I could be wrong.