I'm using MPMoviePlayerController
to play audio/video and would like to continue playing when the app backgrounds and lock screen comes on. I'm setting MPNowPlayingInfoCenter's nowPlayingInfo in viewDidLoad
and again on UIApplicationWillResignActiveNotification
1 notification with the following:
- (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];
}
The lock screen shows the current info, but it's not playing at all. The elapsed time seems about right, but the total playable time is incorrect. Pressing play doesn't start it either. I'm not sure what's wrong, any thoughts?