iosxcodeavplayermpremotecommandcenter

MPRemoteCommandCenter disabled all controls


Hello dear colleagues i need your help. When i add MPChangePlaybackPositionCommand all my controls (Play/Pause/Rew/Next track on lockscreen) has been disabled automatically. Slider of Playback on lockscreen works perfectly but i can not push no one controls button for why - i don't know.

Also i tried this:

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

My code is very easy:

 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


Solution

  • Let's take the play / pause button as an example. It is not enough to enable it. You also have to implement it (I apologize for writing in Swift; I am too lazy to translate back into Objective-C, but you can surely see the point):

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

    and so forth, along with actual doPlay and doPause implementations.