Skip to content

Commit

Permalink
- add api to set now playing artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Jan 18, 2024
1 parent f8f6983 commit aed16ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/pen/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ namespace pen
void music_close_file(const music_file& file);
void music_enable_remote_control();
void music_set_now_playing(const Str& artist, const Str& album, const Str& track);
void music_set_now_playing_artwork(void* data, u32 w, u32 h, u32 bpp, u32 row_pitch);

} // namespace pen
28 changes: 28 additions & 0 deletions core/pen/source/ios/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,32 @@ void music_set_now_playing(const Str& artist, const Str& album, const Str& track
[info release];
}
}

void music_set_now_playing_artwork(void* data, u32 w, u32 h, u32 bpp, u32 row_pitch)
{
@autoreleasepool {
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
auto bmp = CGBitmapContextCreate(
data, (size_t)w, (size_t)h, (size_t)bpp, (size_t)row_pitch, space, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);

CFRelease(space);

CGImageRef cgimg = CGBitmapContextCreateImage(bmp);
CGContextRelease(bmp);

UIImage* uiimg = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);

MPMediaItemArtwork* artwork = [[MPMediaItemArtwork alloc] initWithImage: uiimg];
NSDictionary* info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];

NSMutableDictionary* mut_info = [[NSMutableDictionary alloc] init];
[mut_info setObject:info[MPMediaItemPropertyTitle] forKey:MPMediaItemPropertyTitle];
[mut_info setObject:info[MPMediaItemPropertyAlbumTitle] forKey:MPMediaItemPropertyAlbumTitle];
[mut_info setObject:info[MPMediaItemPropertyArtist] forKey:MPMediaItemPropertyArtist];
[mut_info setObject:artwork forKey:MPMediaItemPropertyArtwork];

[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mut_info];
}
}
}

0 comments on commit aed16ce

Please sign in to comment.