2012-03-17 41 views
0

playpauseAction方法執行它會播放音頻文件以及加載多個viewcontrollers如何檢查是否audioplayer被暫停,同時加載多個viewcontrollers

-(void)playpauseAction:(id)sender 
{ 

if 

    ([audioPlayer isPlaying]){ 

[sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateSelected]; 

     [audioPlayer pause]; 

    } else { 

[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; 

     [audioPlayer play]; 

     self.timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:@selector(displayviewsAction:) userInfo:nil repeats:NO]; 
    } 

} 

在加載這些view controllers只想在每一個viewcontroller,如果audioplayer檢查暫停然後invalidate timer如果沒有則繼續viewcontroller裝載有NSTimer

- (void)displayviewsAction:(id)sender 
{ 

FirstViewController *viewController = [[FirstViewController alloc] init]; 

viewController.view.frame = CGRectMake(0, 0, 320, 480); 

[self.view addSubview:viewController.view]; 

[self.view addSubview:toolbar]; 

if 

    ([audioPlayer pause]){ 

    [timer invalidate]; 

    } else { 

    self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(secondViewController) userInfo:nil repeats:NO]; 

} 
[viewController release]; 
} 

我的問題是當我在displayviewAction方法中添加if語句時,它給我的紅色警告信息是statement requires expression of scalar type (void invalid)

但是if statementplaypauseAction工作正常。

爲什麼if statementdisplayviewAction正在發出紅色警告消息。

回答

1

AVAudioPlayer的暫停被定義爲:

-(void)pause 

這樣寫:

if([audioPlayer pause]) {...} 

對應寫:

if(void) {...}

和空是不是標類型,錯誤到底是什麼消息告訴你。

可能是你的意圖是要檢查的音頻播放暫停,那就是它是不是在玩:

if([audioPlayer isPlaying]==NO) {...} 
相關問題