1

I have a simple video player (just an AVPlayer, playing an M3U8 video file) and I previously got it playing background audio just fine using the following:

    NSError *audioError;
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&audioError];
    if (audioError == nil)
    {
        [[AVAudioSession sharedInstance] setActive:YES error:nil];
    }

Now I would like to customize which buttons are displayed on the lock screen, information about the video being played, and the behavior of those buttons when pressed. I tried the following, but no luck:

    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

    [commandCenter.pauseCommand setEnabled:NO];
    [commandCenter.playCommand setEnabled:NO];
    [commandCenter.stopCommand setEnabled:NO];

    [commandCenter.togglePlayPauseCommand setEnabled:YES];
    [commandCenter.togglePlayPauseCommand addTarget:self action:@selector(togglePlayPause)];

    // These were previously "NO", but I set them to "YES" and re-compiled
    // to see if I was having ANY effect on the buttons
    [commandCenter.nextTrackCommand setEnabled:YES];
    [commandCenter.previousTrackCommand setEnabled:YES];
    [commandCenter.changeRepeatModeCommand setEnabled:YES];
    [commandCenter.changeShuffleModeCommand setEnabled:YES];

    [commandCenter.changePlaybackRateCommand setEnabled:YES];
    [commandCenter.changePlaybackRateCommand addTarget:self action:@selector(changePlaybackRate)];

    [commandCenter.seekBackwardCommand setEnabled:NO];
    [commandCenter.seekForwardCommand setEnabled:NO];

    // These next two were previously "YES", but I set them to "NO" and
    // re-compiled for the same reason as above
    [commandCenter.skipBackwardCommand setEnabled:NO];
    [commandCenter.skipBackwardCommand addTarget:self action:@selector(skipBackward)];

    [commandCenter.skipForwardCommand setEnabled:NO];
    [commandCenter.skipForwardCommand addTarget:self action:@selector(skipForward)];

    if (@available(iOS 9.1, *))
    {
        [commandCenter.changePlaybackPositionCommand setEnabled:YES];
        [commandCenter.changePlaybackPositionCommand addTarget:self action:@selector(changePlaybackPosition)];
    }

    // Previously "NO", but I just wanted to see if ANY buttons
    // would show up
    [commandCenter.ratingCommand setEnabled:YES];
    [commandCenter.likeCommand setEnabled:YES];
    [commandCenter.dislikeCommand setEnabled:YES];
    [commandCenter.bookmarkCommand setEnabled:YES];
    [commandCenter.enableLanguageOptionCommand setEnabled:YES];
    [commandCenter.disableLanguageOptionCommand setEnabled:YES];

    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                                             @"Test", MPMediaItemPropertyTitle,
                                                             @"Artist", MPMediaItemPropertyArtist,
                                                             [NSNumber numberWithDouble:1.0], MPNowPlayingInfoPropertyPlaybackRate,
                                                             nil];

Despite this, my lock screen still looks like so:

enter image description here

It seems like MPRemoteCommandCenter and MPNowPlayingInfoCenter may not work as described

What am I doing wrong?

stevendesu
  • 15,753
  • 22
  • 105
  • 182

0 Answers0