Here is a fairly complete solution for this that I just implemented:
Define vars first to hold both buttons:
@property (weak, nonatomic) IBOutlet UIToolbar *toolbar; @property (strong, nonatomic) IBOutlet UIBarButtonItem *playButton; @property (strong, nonatomic) IBOutlet UIBarButtonItem *pauseButton;
(I understand that the toolbar is a weak ref, because it is defined through IB, and it has a strong pointer to it, but the play / pause buttons are strong pointers, because we create them below. Fu is a little weak on this front as a pretty newbie , so the fixes were appreciated.)
Secondly, in IB, create a play button (without a pause button) and bind it to the previous version of playButton var.
Third, configure this method:
- (void) setAsPlaying:(BOOL)isPlaying { self.rootViewController.playing = isPlaying;
Fourth, call setAsPlaying wherever you are going to play or in pause mode. For example:
-(IBAction) playAudio:(id)sender { [self.audioPlayer play]; [self setAsPlaying:YES]; } -(IBAction) pauseAudio:(id)sender { [self.audioPlayer pause]; [self setAsPlaying:NO]; }
mowliv
source share