gpt4 book ai didi

ios - MPRemoteCommandCenter 禁用所有控件

转载 作者:行者123 更新时间:2023-11-28 23:32:36 32 4
gpt4 key购买 nike

亲爱的同事们,您好,我需要您的帮助。当我添加 MPChangePlaybackPositionCommand 时,我的所有控件(锁定屏幕上的播放/暂停/倒播/下一首轨道)已自动禁用。锁屏上的播放 slider 工作得很好,但我无法按下任何一个控制按钮,这是为什么 - 我不知道。

我也试过这个:

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

enter image description here

最佳答案

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

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

等等,以及实际的 doPlaydoPause 实现。

关于ios - MPRemoteCommandCenter 禁用所有控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55973976/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com