我MPMoviePlayerController
用来播放音频/视频,并希望在应用程序背景和锁定屏幕出现时继续播放。我将 MPNowPlayingInfoCenter 的 nowPlayingInfo 设置viewDidLoad
在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];
}
锁定屏幕显示当前信息,但根本没有播放。经过的时间似乎正确,但总可玩时间不正确。按播放也不会启动它。我不确定出了什么问题,有什么想法吗?