ios - MPRemoteCommandCenter control center pause button doesn't update even after the audio file is paused -


i’m working on audio recording application deals mpremotecommandcenter class. i’ve setup command center play , pause commands. code snippet added below. i’m facing issue pausecommand.

from application start playing audio file updates control center file being played , play button changed pause button. when file being played, pause audio control center choosing pause button. invoking pausecommand handler in application , audio file paused control centre continuous update seek bar , pause button doesn’t change play button.

-(void) setupremotecontrols { mpremotecommandcenter *commandcenter = [mpremotecommandcenter sharedcommandcenter];  [commandcenter.pausecommand addtargetwithhandler:^mpremotecommandhandlerstatus(mpremotecommandevent *event) {      if ([self pauseaudioplayback])          return mpremotecommandhandlerstatussuccess;     else         return mpremotecommandhandlerstatuscommandfailed; } ];  [commandcenter.playcommand addtargetwithhandler:^mpremotecommandhandlerstatus(mpremotecommandevent *event) {      if ([self resumeaudioplayback])         return mpremotecommandhandlerstatussuccess;     else         return mpremotecommandhandlerstatuscommandfailed; } ]; 

}

// method invoked in both pauseaudioplayback & resumeaudioplayback methods

- (void) updateremotecontrols { mpremotecommandcenter *commandcenter = [mpremotecommandcenter sharedcommandcenter];  if (self.audioplayer) {     if (self.isplaying)         commandcenter.playcommand.enabled = no;     else if (self.isplaypaused)         commandcenter.playcommand.enabled = yes; } else     [self clearnowplayinginfo]; 

}

please let me know if additional information required.

for ios 9.2:

i've tried combinations of settings in mpnowplayinginfocenter , mpremotecommandcenter.

to stop updating seek bar enough set

mpnowplayinginfocenter.defaultcenter().nowplayinginfo?[mpnowplayinginfopropertyplaybackrate] = 0.0 mpnowplayinginfocenter.defaultcenter().nowplayinginfo?[mpnowplayinginfopropertyelapsedplaybacktime] = player?.currenttime 

but toggle pause button needed deactivate avaudiosession after pausing audioplayback.

avaudiosession.sharedinstance().setactive(false) 

finally pausecommand handler looks like:

mpremotecommandcenter.sharedcommandcenter().pausecommand.addtargetwithhandler { (e) -> mpremotecommandhandlerstatus in         player?.pause()         let infocenter = mpnowplayinginfocenter.defaultcenter()         infocenter.nowplayinginfo?[mpnowplayinginfopropertyplaybackrate] = 0.0         infocenter.nowplayinginfo?[mpnowplayinginfopropertyelapsedplaybacktime] = player?.currenttime          _ = try? avaudiosession.sharedinstance().setactive(false)          return mpremotecommandhandlerstatus.success } 

hope, helps somebody.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -