Toggle between play/pause UIButtons
<p>i have created two UIButtons and only play button is appearing on the UIToolbar. In the play method i want is when play button is pressed it shows pause button and if user presses pause button it pauses the audiofile and then shows the play button. </p>

<pre><code>UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];

[playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];

playButton.frame = CGRectMake(0, 0, 50, 50);

UIImage *image = [UIImage imageNamed:@"play.png"];

[playButton setImage:image forState:UIControlStateNormal];

UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:playButton];



UIButton *pauseButton = [UIButton buttonWithType:UIButtonTypeCustom];

 [pauseButton addTarget:self action:@selector(pause:) forControlEvents:UIControlEventTouchUpInside];

pauseButton.frame = CGRectMake(0, 0, 50, 50);

UIImage *imge = [UIImage imageNamed:@"pause.png"];

[pauseButton setImage:imge forState:UIControlStateNormal];

-(void)play:(id)sender 
{

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"theme" 
                                                     ofType:@"mp3"];

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

audioPlayer = [[AVAudioPlayer alloc] 
              initWithContentsOfURL:fileURL error:nil];

audioPlayer.currentTime = 0;

[audioPlayer play];

[fileURL release];  

}
</code></pre>

<p>I need help in implementing this</p>

<p>In the play method</p>

<p>i did</p>

<pre><code>[audioPlayer play];

UIImage *imge = [UIImage imageNamed:@"pause.png"];

[pauseButton setImage:imge forState:UIControlStateNormal];

[audioPlayer pause];

UIImage *image = [UIImage imageNamed:@"play.png"];

[playButton setImage:image forState:UIControlStateNormal];

[audioPlayer Play];
</code></pre>

<p>I think i m doing wrong way</p>

<p>Please advice .</p>

<p>Thanks for help.</p>

<p>Thanks</p>
