1

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 UIApplicationWillResignActiveNotification1 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?

Duck
  • 34,902
  • 47
  • 248
  • 470
1192805
  • 988
  • 2
  • 10
  • 26
  • This may help you: http://stackoverflow.com/questions/22591421/ios-background-audio-not-playing. – keyboard Jan 12 '15 at 16:57
  • Thanks, found answer here http://stackoverflow.com/questions/9445604/mpmovieplayercontroller-playing-audio-stream-in-the-background – 1192805 Jan 14 '15 at 03:20

0 Answers0