Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-30-2011, 07:33 AM   #1 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Post AVAudioPlayer multiple sounds at the same time

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

}
sacha1996 is offline   Reply With Quote
Old 03-30-2011, 11:17 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: Tokyo
Posts: 163
kazbluesky is on a distinguished road
Default

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 View Post
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];

}
kazbluesky is offline   Reply With Quote
Old 03-30-2011, 01:31 PM   #3 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by kazbluesky View Post
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

Thanks man !
sacha1996 is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, avaudioplayer, cocoa objective c iphone, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 366
11 members and 355 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:36 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0