2012-10-10 47 views
0

我正在製作一個音板應用程序,我使用的聲音持續時間超過30秒。我通過在IB中將我的動作與「降落」事件連接起來播放聲音,但是一旦開始播放,聲音就會繼續播放。我在某個按鈕上連接了一個「touch cancel」&「touch up outside」事件,該事件應該會停止聲音,但由於某種原因它不會。 任何人都可以提供解決我的問題嗎?音板應用程序:只要用戶按下按鈕播放聲音

---編輯--- 這裏是我的代碼:

-(IBAction)playSound:(id)sender { 
    NSString *soundFile; 
    soundFile = [[NSBundle mainBundle] pathForResource:@"testSound" ofType:@"mp3"]; 
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFile] error:nil]; 
    audioPlayer.volume = volumeSlider.value; 
    audioPlayer.numberOfLoops = -1; 
    [audioPlayer prepareToPlay]; 
    [audioPlayer play]; 
} 

-(IBAction)stopSound:(id)sender { 
    [audioPlayer stop]; 
} 

回答

0

「潤色外」是指當按鈕被按下,並且用戶的手指無法控制的移動和電梯。

這聽起來像你正在尋找「觸摸」事件。

但是,只要您確定,您應該發佈您用來啓動和停止聲音的代碼。

1

我所做的是在按下一個按鈕即可(執行我的行動evernt),我迷上了動作1)觸摸向下2)觸摸拖動輸入

要關閉按鈕關閉(取消操作)我添加到按鈕 - 1)內部觸摸2)外部觸摸3)觸摸取消4)觸摸拖動退出