2013-07-17 52 views
0

請記住,我是一個新手,因此不是很有經驗:我有幾個音頻文件播放按鈕觸發,每按一次按鈕,所有其他聲音停止。現在我想創建一個按鈕來停止當前正在播放的內容。另外,每按一次按鈕,音樂就不會從頭開始,而是從中斷的時間點開始。謝謝你在前進,這裏是一個片段:一鍵停止所有音頻AVAudioPlayer

- (IBAction)playSound1 { 
if ((self.sound2Player.playing) || (self.sound3Player.playing)|| (self.sound4Player.playing)||(self.sound5Player.playing)||(self.sound6Player.playing)||(self.sound7Player.playing)) 
    [self.sound2Player stop]; 
    [self.sound3Player stop]; 
    [self.sound4Player stop]; 
    [self.sound5Player stop]; 
    [self.sound6Player stop]; 
    [self.sound7Player stop]; 
    [self.sound2Player stop]; 

[self.sound1Player play]; 

回答

1

請使用

- (IBAction)stopSound 
{ 

    [self.sound1Player stop]; 
    [self.sound2Player stop]; 
    [self.sound3Player stop]; 
    [self.sound4Player stop]; 
    [self.sound5Player stop]; 
    [self.sound6Player stop]; 
    [self.sound7Player stop]; 
    [self.sound2Player stop]; 
} 

如果你再想玩的地方停下,爲什麼你停止播放器上使用[avPlayer pause]去上班的[self.avPlayer stop];那麼當你再次玩時,他們會從你阻止他們的地方開始。

+0

謝謝,它的工作原理。奇怪的是,停止命令實際上暫停了它們,也就是說,聲音文件從停止的位置開始播放,並且不從一開始就循環播放...... –

+0

我把它塞了下來,再次感謝你......我設置了currentime爲0 ....祝你有美好的一天! –

+0

@NicolaLoverre你應該接受這個答案,如果這對你有幫助。 –