我有一个简单的视频播放器(只是一个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
可能无法按所述操作
我在做什么错了?