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 04-01-2009, 09:33 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default Stopping Sound and Controlling Volume

I have an app that simply plays a short .wav file on the click of a button and would like it to also stop the sound at the click of another button and implement a slider for control of the volume. Im using the AudioToolbox/AudioServices file and my code for playing the sound looks like this:

- (IBAction)push {
NSString *tmpFileName = [[NSString alloc] initWithFormat:@"mario_09"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];

SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];

}

any help would be greatly appreciated. thanks much.
starwarsdevwookie59 is offline   Reply With Quote
Old 04-01-2009, 10:27 AM   #2 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 101
MikeBlah is on a distinguished road
Default

i had the same issue and added this just above the code for the next button that was pressed that needed to cancel any sound currently playing:

[soundEffect release];

now i can click button one and mid sound press button two and have sound 1 canceled and sound 2 played.
MikeBlah is offline   Reply With Quote
Old 04-01-2009, 10:42 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default

Thanks, what do i replace soundEffect with? my file name or SoundID or what?
starwarsdevwookie59 is offline   Reply With Quote
Old 04-01-2009, 03:18 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 101
MikeBlah is on a distinguished road
Default

Quote:
Originally Posted by starwarsdevwookie59 View Post
Thanks, what do i replace soundEffect with? my file name or SoundID or what?
I think for you it will be soundID
MikeBlah is offline   Reply With Quote
Old 04-01-2009, 03:29 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default

- (IBAction)push {
NSString *tmpFileName = [[NSString alloc] initWithFormat:@"mario_09"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];

SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];

}

- (IBAction)stop {

[soundID release];
(ERROR SOUNDID UNDECLARED)

NSString *tmpFileName = [[NSString alloc] initWithFormat:@"mario_08"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];

SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];

}

I did this but i got the error listed above in all caps.
starwarsdevwookie59 is offline   Reply With Quote
Old 08-13-2010, 05:33 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
felixdkatt is on a distinguished road
Default try this

you need to declare soundID as an instance variable. when you declare it in the function its only available in that function. so create a instance variable at the top then you dont need to put SystemSoundID soundID; everywhere

SystemSoundID *soundID;

- (IBAction)push {
NSString *tmpFileName = [[NSString alloc] initWithFormat:@"mario_09"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];


AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];

}

- (IBAction)stop {

[soundID release];


NSString *tmpFileName = [[NSString alloc] initWithFormat:@"mario_08"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];


AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);

[tmpFileName release];

}

I did this but i got the error listed above in all caps.[/quote]
felixdkatt is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, slider, sound, stop

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: 327
5 members and 322 guests
blueorb, guusleijsten, Kryckter, LEARN2MAKE, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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