0

I've successfully managed to get music controls in lockscreen while playing with AVPlayer but the issue is that I would like to change UIButon image when the user press the play / pause button in lockscreen (according to the player state). Thanks to this, if the user unlock the device while the player is paused, the UIButton's image represent the state.

I can do everything I want through these actions but it seems that UI changes are impossible...

Does it is possible or not ?

Thanks in advance !

EDIT : here is the code I use for changing the UIButton's image while in app (that doesn't work while in lockscreen):

[self.playButton setImage:[UIImage imageNamed:@"Pause-100.png"] forState:UIControlStateNormal];
Synny
  • 542
  • 1
  • 4
  • 18

1 Answers1

0

I've found the solution by adding an observer for when the app did become active

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateGUI)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:[UIApplication sharedApplication]];

Then I run this method to update the UIButton's image :

- (void)updateGUI {

if (isPaused) {

    [self.playButton setImage:[UIImage imageNamed:@"Play-100.png"] forState:UIControlStateNormal];

}else if (!isPaused) {

   [self.playButton setImage:[UIImage imageNamed:@"Pause-100.png"] forState:UIControlStateNormal];

}

}

Synny
  • 542
  • 1
  • 4
  • 18