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 05-25-2011, 02:57 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 138
rrichar is on a distinguished road
Default How do you add a Mute Button/Volume Slider when using AVAUDIOPLAYER...

How do you add a Mute Button/Volume Slider when using AVAUDIOPLAYER... I have an app with 20 sound buttons across four tabs. I need to add a volume slider for each tab or a mute button for each tab. I also wanted to know if there is a way to set how loud a sound button can be. For Example if I have the following Button:

Code:
-(IBAction) Sound:(id)sender{
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"];
	AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	
	theAudio.delegate=self;
	[theAudio play];
}
And I want this sound button to play at the half the volume compare to other audio buttons what do I do ?

Last edited by rrichar; 05-25-2011 at 04:17 PM.
rrichar is offline   Reply With Quote
Old 05-25-2011, 07:17 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by rrichar View Post
How do you add a Mute Button/Volume Slider when using AVAUDIOPLAYER... I have an app with 20 sound buttons across four tabs. I need to add a volume slider for each tab or a mute button for each tab. I also wanted to know if there is a way to set how loud a sound button can be. For Example if I have the following Button:

Code:
-(IBAction) Sound:(id)sender{
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"];
	AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	
	theAudio.delegate=self;
	[theAudio play];
}
And I want this sound button to play at the half the volume compare to other audio buttons what do I do ?
The docs say that AVAudioPlayer has a volume property. It doesn't say if it allows you to change the volume while a sound is playing or not, but I think it probably does.

You need to create a slider in IB, and connect to an action with for the UIControlEventValueChanged event. In that action method, get the value of the slider and set the volume property of your audio player.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 05-26-2011, 02:53 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

should be just

Quote:
theAudio.volume = 0.5; // 0.0 mute; 1.0 max volume
__________________
dany_dev is offline   Reply With Quote
Old 05-26-2011, 11:47 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 138
rrichar is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
should be just
I have serveral buttons that play sound and execute other code. If I want to add a mute button must I create a IABACTION and then add theAudio.volume = 0; for every button.
rrichar is offline   Reply With Quote
Old 05-26-2011, 11:51 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by rrichar View Post
I have serveral buttons that play sound and execute other code. If I want to add a mute button must I create a IABACTION and then add theAudio.volume = 0; for every button.
Create a single IBAction and connect all your mute buttons to the same action.

If each mute button is supposed to mute a different sound, but tags on the buttons, and have the action get the tag value and use that to figure out which sound to mute.

(Make your action look like this:

Code:
- (IBAction) muteButtonAction: (id) sender;
{
  int button_tag;
  button_tag = [sender tag];
  //Figure out which sound to mute based on the tag
}
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-12-2012, 06:29 AM   #6 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 18
cipher255 is on a distinguished road
Default background music

hi i am working on a single view based app ,and was wondering in xcode 4.2 can you apply this code under the -(void)viewDidLoad so when the app starts up background music can play?

NSString *path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"];

AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];

theAudio.delegate=self;
[theAudio play];
cipher255 is offline   Reply With Quote
Old 01-12-2012, 06:54 AM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by cipher255 View Post
hi i am working on a single view based app ,and was wondering in xcode 4.2 can you apply this code under the -(void)viewDidLoad so when the app starts up background music can play?

NSString *path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"];

AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];

theAudio.delegate=self;
[theAudio play];

Should work. Why not try it yourself?

BTW, you should put the sound player object into a property so you can stop it, adjust the volume, etc. If you just create it as a local variable, you have no way to reference the audio player object once you exit your viewDidLoad method.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 01-12-2012 at 10:07 PM.
Duncan C is offline   Reply With Quote
Old 01-12-2012, 05:07 PM   #8 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Should work. Why not try it yourself?

BTW, you should put the sound player object into a property so you can stop it, adjust the volume, etc. If you just create it as an instance variable, you have no way to reference the audio player object once you exit your viewDidLoad method.
I think you mean a local variable.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 01-12-2012, 10:07 PM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Domele View Post
I think you mean a local variable.
Good catch. I fixed it in my post. I guess I got distracted while writing that.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C 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: 349
6 members and 343 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
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 02:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0