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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 02-09-2010, 03:20 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 14
Default How to stop a sound if another action is called

Hi guys,

I'm just starting to get into iPhone development myself, and have a quick question that I hope someone can help me out with.

I have the code below that plays a sound when the connected button is pressed:

Code:
- (IBAction)playsound1 {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"FILENAME" ofType:@"mp3"];
	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
}
What I want to do is add some code to this so that if another button is pressed, it stops the above sound, while the other sound starts.

Can anyone help me out with this?

Thanks in advance

Last edited by edcousins; 02-09-2010 at 06:43 AM.
edcousins is offline   Reply With Quote
Old 10-09-2010, 12:13 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 10
Default

did you find a solution to this? I'm looking to do something similar. stop the audio if the user changes views.

thanks
hanumandev is offline   Reply With Quote
Old 10-09-2010, 12:56 PM   #3 (permalink)
Hot Cocoa Touch
 
redon's Avatar
 
Join Date: Oct 2009
Location: Florida
Posts: 193
Default

Quote:
Originally Posted by edcousins View Post
Hi guys,

I'm just starting to get into iPhone development myself, and have a quick question that I hope someone can help me out with.

I have the code below that plays a sound when the connected button is pressed:

Code:
- (IBAction)playsound1 {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"FILENAME" ofType:@"mp3"];
	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
}
What I want to do is add some code to this so that if another button is pressed, it stops the above sound, while the other sound starts.

Can anyone help me out with this?

Thanks in advance
Code:
[theAudio stop];
[theAudio release];
__________________
http://www.bugspray.me/
Search GetFit! on the App Store.
redon is offline   Reply With Quote
Reply

Bookmarks

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: 255
24 members and 231 guests
ADY, bookesp, chillyh, ckgni, dacapo, Dani77, Davey555, Desert Diva, Dominus, glenn_sayers, HemiMG, JasonR, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, prchn4christ, Raggou, Rudy, ryantcb, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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