The way I solved this same problem was to have 2 seperate AVplayers. Call one theAudio and the other theAudio2 then both will play over each other (or as many as you make).
The code that is stopping your player each time is
if (theAudio) [theAudioRelease];
You can just remove this line, but then you will have another problem which is that the sound file will play for as many times as you tapped the button, which is not ideal and feels very inexact and clunky.
I'm new to all this, but the top one worked for me.
Good Luck
Quote:
Originally Posted by sacha1996
Hi , I'm trying to make a sound app ,
But when I press sound 2 while sound 1 is playing , than sound 1 is stopping.
I want that the user can play multiple sounds at the same time.
But the problem is I don't know how to do that.
Can someone help me please ?
Thanks
Code :
Code:
-(IBAction)pushButton {
NSString *path = [[NSBundle mainBundle] pathForResource:@"App1" ofType:@"mp3"];
if(theAudio)[theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
-(IBAction)pushButton2 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"App2" ofType:@"mp3"];
if(theAudio)[theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
|