tags:

views:

9

answers:

0

I have a transition based app I decided to expand my app and add audio but one issue with the audio does not let me move on.

When I add the different sounds (one for each view) to more the the two views I keep getting the 2nd, 3rd and 4th sound etc. all mixed together instead of the next sound playing on its own.code below is little sample of the rest of the rest of the audio code.

I added [sound1 stop]; [sound2 stop]; [sound3 stop];etc but then I get no sound at all, I have release for each and still get the same results.

-(IBAction)playSound1 {



        NSString *path1 = [[NSBundle mainBundle]pathForResource:@"sound1" ofType:@"m4a"];

        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path1];

        AVAudioPlayer* sound1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error:NULL];

        sound1.delegate = self;

        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

        [sound1 prepareToPlay];

        [sound1 play];



        NSString *path2 = [[NSBundle mainBundle]pathForResource:@"sound2" ofType:@"m4a"];

        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path2];

        AVAudioPlayer* sound2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error:NULL];

        Sound2.delegate = self;

        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

        [sound2 prepareToPlay];

        [sound2 play];



        NSString *path3 = [[NSBundle mainBundle]pathForResource:@"sound3" ofType:@"m4a"];

        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path3];

        AVAudioPlayer* sound3 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error:NULL];

        Sound3.delegate = self;

        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

        [sound3 prepareToPlay];

        [sound2 play];







 **********Call the different sounds at each transition*************



        UIImageView *tmp = view2;

        View2 = view1;

        [self playSound2];

        View1 = tmp;



        UIImageView *tmp1 = view3;

        View3 = view2;

        [self playSound3];

        View2 = tmp1;



        UIImageView *tmp1 = view4;

        View4 = view3;

        [self playSound4];

        View3 = tmp1

I have looked at the various audio sample and read through the guide and tried everything I though may work but nothing!!

Thanks