I am developing a html5 webview app playing youtube videos from a playlist (controlled with JavaScript). Now i want to change the displayed title, artist and other information in iOS InfoCenter using this code:
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
[songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
It works for a second but then iOS replaces my set information (title and artist) again with the original youtube title and the video url. Is there a way to permanently overwrite this information with my own?
Thank You!
A bit hacky, but you need set a notification listener for AVPlayerItemNewAccessLogEntry
Like so:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemWasSet:)
name:@"AVPlayerItemNewAccessLogEntry"
object:nil];
}
and then
-(void)playerItemWasSet:(NSNotification *)note {
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
[songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
}
I don't know whether Apple will have a problem with it or not, I've not submitted an app with this in. Just tried it out for fun.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With