0

你好亲爱的同事我需要你的帮助。当我添加 MPChangePlaybackPositionCommand 时,我的所有控件(锁定屏幕上的播放/暂停/重播/下一曲目)都已自动禁用。锁屏上的播放滑块运行良好,但我无法按下任何控制按钮,原因是 - 我不知道。

我也试过这个:

[[MPRemoteCommandCenter sharedCommandCenter].playCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand setEnabled:YES]; 

我的代码很简单:

 MPChangePlaybackPositionCommand *changePlaybackPositionCommand = [[MPRemoteCommandCenter sharedCommandCenter] changePlaybackPositionCommand];
    [changePlaybackPositionCommand addTarget:self action:@selector(onChangePlaybackPositionCommand:)];

- (MPRemoteCommandHandlerStatus) onChangePlaybackPositionCommand:
(MPChangePlaybackPositionCommandEvent *) event

{
    [[[PlayerPlistController utilise]miniplayer] seekToTime:CMTimeMakeWithSeconds(event.positionTime, 1)];

    NSLog(@"changePlaybackPosition to %f", event.positionTime);

    return MPRemoteCommandHandlerStatusSuccess;
}

NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

[songInfo setObject:NAME_TITLE forKey:MPMediaItemPropertyTitle];
[songInfo setObject:NAME_TITLE_SLOGON forKey:MPMediaItemPropertyAlbumTitle];

UIImage *image = [UIImage imageNamed:PLACEHOLDER_EMPTY];
MPMediaItemArtwork *imageArt =  [[MPMediaItemArtwork alloc] initWithBoundsSize:image.size requestHandler:^UIImage* _Nonnull(CGSize aSize) { return image; }];

[songInfo setObject:imageArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];

在此处输入图像描述

4

1 回答 1

2

我们以播放/暂停按钮为例。启用它是不够的。你还必须实现它(我很抱歉用 Swift 编写;我懒得翻译回 Objective-C,但你肯定能明白这一点):

let mprc = MPRemoteCommandCenter.shared()
mprc.playCommand.addTarget(self, action:#selector(doPlay))
mprc.pauseCommand.addTarget(self, action:#selector(doPause))

等等,以及实际doPlaydoPause实现。

于 2019-05-03T17:07:16.897 回答