Nicola Loverre
Nicola Loverre

Reputation: 31

one button to stop all audio AVAudioPlayer

please keep in mind that I am a newbie therefore not very experienced: I have several audio files playing triggered by a button, each time a button is pressed, all other sounds stop. Now I want to creadte a button which stops whatever is playing at the moment. Also, each time I press one of the button, the music doesn t start from the beginning, but from the point in time when it was interrupted. Thank you in advance, here is a snippet:

- (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];

Upvotes: 0

Views: 643

Answers (1)

iEinstein
iEinstein

Reputation: 2100

Please use this

- (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];
}

If you again want to play where it stop so why you are stopping the player use [avPlayer pause] to work instead of [self.avPlayer stop]; then when you play again they will start from where you have stopped them.

Upvotes: 1

Related Questions