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.
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];
}
I need help in implementing this
In the play method
i did
[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];
I think i m doing wrong way
Please advice .
Thanks for help.
Thanks
Use only one button with 1 image for each state (Selected and Normal):