獲取{[audioPlayer pause];}
的紅色警告Expected']'
並獲取另一個紅色警告消息[[audioPlayer play];]
說Expected expression
。切換播放/暫停不起作用
UIButton *playpauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playpauseButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
playpauseButton.frame = CGRectMake(0, 0, 50, 50);
[playpauseButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playpauseButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *playpause = [[UIBarButtonItem alloc] initWithCustomView:playpauseButton];
動作代碼:
-(void)playpauseAction:(UIButton *)sender
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"theme"
ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
[fileURL release];
[audioPlayer prepareToPlay];
audioPlayer.currentTime = 0;
//[audioPlayer play];
if
([audioPlayer isPlaying]){
Image:[UIImage imageNamed:@"play.png"] forState:UIControlStateSelected
setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal
{[audioPlayer pause];}
} else {
setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected
Image:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal
[[audioPlayer play]; ]
}
}
我需要解決這個代碼的幫助。
感謝您的幫助。
現在播放按鈕顯示,當我點擊播放按鈕時,它正在播放音頻文件,並將播放按鈕變成暫停按鈕,但當我點擊暫停按鈕來暫停它。它不是暫停,而是從開始播放音頻文件 – user1120133 2012-02-02 18:27:51