我創建了一個使用播放和停止圖像的按鈕,我想要的是當我按播放,聲音結束時,停止圖像應該回去播放,但它不工作,任何人都可以幫助這裏請。乾杯。iPhone - 設置按鈕回到初始狀態
- (IBAction)play {
if(clicked == 0){
clicked = 1;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/TEST.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
[start setImage:[UIImage imageNamed:@"stop.png"] forState:UIControlStateNormal];
}
else{
[audioPlayer release];
clicked = 0;
[start setImage:[UIImage imageNamed:@"pla.png"] forState:UIControlStateNormal];
}
}
//If user does not do anything by the end of the sound set the button to start
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
successfully: (BOOL) flag {
if (flag==YES) {
[start setImage:[UIImage imageNamed:@"pla.png"] forState:UIControlStateNormal];
}
}
這是我的.h文件
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
int clicked;
@interface _0_RabbanasViewController : UIViewController {
IBOutlet UIScrollView *scroll;
AVAudioPlayer *audioPlayer;
IBOutlet UIButton *start;
IBOutlet UIImage *iPla;
IBOutlet UIImage *iStop;
BOOL successfully;
}
- (IBAction)play;
- (IBAction)next;
@end
並設置圖像 「pla.png」 手動工作(按下停機時) ? – fbrozovic
是的,當我點擊播放時,音頻將播放,停止圖像將出現,當我點擊停止時,它將停止音頻並播放。我只是不知道要在什麼時候添加,到達最後,停止應該顯示。 – idipro