Merge pull request #158 from NattyNarwhal/now-playing-more-metadata

Provide more information to MPNowPlayingInfoCenter, including album art
CQTexperiment
Christopher Snowhill 2021-06-21 20:04:46 -07:00 committed by GitHub
commit 0bfd14b0f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -658,6 +658,26 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[songInfo setObject:[entry artist] forKey:MPMediaItemPropertyArtist];
if ([entry album])
[songInfo setObject:[entry album] forKey:MPMediaItemPropertyAlbumTitle];
if ([entry albumArt]) {
// can't do && with @available
if (@available(macOS 10.13.2, *)) {
CGSize artworkSize = CGSizeMake(500, 500);
MPMediaItemArtwork *mpArtwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:artworkSize requestHandler:^NSImage * _Nonnull(CGSize size) {
return [entry albumArt];
}];
[songInfo setObject:mpArtwork forKey:MPMediaItemPropertyArtwork];
}
}
// I don't know what NPIC does with these since they aren't exposed in UI, but if we have them, use it.
// There's a bunch of other metadata, but PlaylistEntry can't represent a lot of it.
if ([entry genre])
[songInfo setObject:[entry genre] forKey:MPMediaItemPropertyGenre];
if ([entry year]) {
// If PlaylistEntry can represent a full date like some tag formats can do, change it
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *releaseYear = [calendar dateWithEra:1 year:[[entry year] intValue] month:0 day:0 hour:0 minute:0 second:0 nanosecond:0];
[songInfo setObject:releaseYear forKey:MPMediaItemPropertyReleaseDate];
}
[songInfo setObject:[NSNumber numberWithFloat:[entry currentPosition]] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[songInfo setObject:[entry length] forKey:MPMediaItemPropertyPlaybackDuration];
[songInfo setObject:[NSNumber numberWithFloat:[entry index]] forKey:MPMediaItemPropertyPersistentID];