1

我有一个简单的视频播放器(只是一个 AVPlayer,播放 M3U8 视频文件),我之前使用以下方法让它播放背景音频就好了:

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

现在我想自定义锁定屏幕上显示哪些按钮、有关正在播放的视频的信息以及这些按钮在按下时的行为。我尝试了以下方法,但没有运气:

    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];

尽管如此,我的锁屏仍然是这样的:

在此处输入图像描述

它看起来像MPRemoteCommandCenter并且MPNowPlayingInfoCenter可能不像描述的那样工作

我究竟做错了什么?

4

0 回答 0