我使用MPMoviePlayerController
播放音频/视频,并希望在应用背景和锁定屏幕亮起时继续播放。我在viewDidLoad
中设置了MPNowPlayingInfoCenter的nowPlayingInfo,并在UIApplicationWillResignActiveNotification
1通知中设置了以下内容:
- (void)appWillResignActive {
NSMutableDictionary *nowPlayingInfo = [[NSMutableDictionary alloc] init];
[nowPlayingInfo setObject:_session[@"session"][@"title"] forKey:MPMediaItemPropertyTitle];
[nowPlayingInfo setObject:_session[@"session"][@"author"] forKey:MPMediaItemPropertyArtist];
[nowPlayingInfo setObject:_session[@"session"][@"album"] forKey:MPMediaItemPropertyAlbumTitle];
[nowPlayingInfo setObject:[NSNumber numberWithDouble:_videoController.playableDuration] forKey:MPMediaItemPropertyPlaybackDuration];
[nowPlayingInfo setObject:@(1.0f) forKey:MPNowPlayingInfoPropertyPlaybackRate];
[nowPlayingInfo setObject:[NSNumber numberWithDouble:_videoController.currentPlaybackTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
if (_session[@"session"][@"album_art"] != nil) {
UIImage *albumArtImage = [UIImage imageNamed:_session[@"session"][@"album_art"]];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:albumArtImage];
[nowPlayingInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
}
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlayingInfo];
}
锁定屏幕显示当前信息,但它根本没有播放。经过的时间似乎是正确的,但总的可玩时间是不正确的。按下播放也不会启动它。我不确定是什么错,有什么想法吗?