我正在尝试在控制中心显示音频详细信息,如所附屏幕截图所示。
使用以下代码,它可以在除 iOS11 之外的所有 iOS 版本中按预期工作:
if ([MPNowPlayingInfoCenter class]) {
NSString *progress = (appDelegate.audioPlayer.progress == 0 || appDelegate.audioPlayer == nil ) ? @"0.0" : [NSString stringWithFormat:@"%f",appDelegate.audioPlayer.progress];
NSString *duration = (appDelegate.audioPlayer.progress == 0 || appDelegate.audioPlayer == nil ) ? @"0.0" :[NSString stringWithFormat:@"%f",appDelegate.audioPlayer.duration];
UIImage *image;
if (appDelegate.selectedImg.length == 0 || appDelegate.selectedImg == nil) {
image = [UIImage imageNamed:@"Music_Logo_1_"];
}
else{
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.selectedImg]];
image = [UIImage imageWithData:data] != nil ? [UIImage imageWithData:data] : [UIImage imageNamed:@"Music_Logo_1_"];
}
NSDictionary *currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:appDelegate.selectedTitle != nil && ![appDelegate.selectedTitle isEqualToString:@""] ? appDelegate.selectedTitle : @"", appDelegate.selecteddesc != nil && ![appDelegate.selecteddesc isEqualToString:@""] ? appDelegate.selecteddesc : @"", progress , duration,[[MPMediaItemArtwork alloc] initWithImage:image],@"Music", nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle,MPMediaItemPropertyAlbumTitle, MPNowPlayingInfoPropertyElapsedPlaybackTime ,MPMediaItemPropertyPlaybackDuration, MPMediaItemPropertyArtwork,MPMediaItemPropertyArtist, nil]];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
}
MPNowPlayingInfoCenter
属性不适用于 iOS 11,而 iOS 11 在较低版本的 iOS 中按预期工作。
iOS 11 中的输出:
预期结果:
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)