【发布时间】:2012-02-02 16:53:33
【问题描述】:
收到{[audioPlayer pause];}saying 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]; ]
}
}
我需要帮助来修复此代码。
感谢您的帮助。
【问题讨论】:
标签: iphone cocoa-touch avfoundation avaudioplayer