Soundboard app: Play sound as long as the user is pressing the button

Posted by Pantelis Proios on Stack Overflow See other posts from Stack Overflow or by Pantelis Proios
Published on 2012-10-10T22:15:33Z Indexed on 2012/10/19 5:02 UTC
Read the original article Hit count: 177

Filed under:
|
|

I am making a soundboard app and i am using sounds with over 30sec duration. I am playing the sound by connecting in IB my action with a "touch down" event, however the sound keeps playing once started. I connected in the some button a "touch cancel" & "touch up outside" event that is supposed to stop the sound but for some reason it doesn't. Can anybody provide a solution to my problem?

---Edit--- Here is my code:

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

© Stack Overflow or respective owner

Related posts about xcode

Related posts about touch