diff --git a/core/pen/include/os.h b/core/pen/include/os.h index a5039e09..86cafd42 100644 --- a/core/pen/include/os.h +++ b/core/pen/include/os.h @@ -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 diff --git a/core/pen/source/ios/os.mm b/core/pen/source/ios/os.mm index d87838f6..ef7d5b1a 100644 --- a/core/pen/source/ios/os.mm +++ b/core/pen/source/ios/os.mm @@ -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]; + } + } }