code to play sound programmatically using a button on the iphone

Posted by Brandon on Stack Overflow See other posts from Stack Overflow or by Brandon
Published on 2010-04-13T00:27:21Z Indexed on 2010/04/13 0:32 UTC
Read the original article Hit count: 362

I am trying to figure out how to hook up a button to play a sound programmatically without using IB. I have the code to play the sound, but have no way of hooking the button up to play the sound? any help?

here is my code that I'm using:

     - (void)playSound
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"boing_1" ofType:@"wav"];
        AVAudioPlayer* myAudio = [[AVAudioPlayer alloc] 
                 initWithContentsOfURL:[NSURL fileURLWithPath:path error:NULL]];
        myAudio.delegate = self;
        myAudio.volume = 2.0;
        myAudio.numberOfLoops = 1;
        [myAudio play];
    }

© Stack Overflow or respective owner

Related posts about sound

Related posts about iphone