Setting AVAudioPlayer volume to the user's ring volume? - iphone

I'm having a problem with AVAudioPlayer's volume.
I can set theAudio.volume property to 1.0, but I'd rather just play the audio at the volume the user has his iphone ringer set to.
Getting rid of the volume property defaults it at 1.0.
This seems trivial, but I couldn't find a reference to it anywhere.
Thanks a bunch!

The volume you set to a AVAudioPlayer instance is just a relative volume, for example if you wanna play two sounds, one at half volume of the other, you set the first one to 0.5 and the second to 1.0.
The real device volume is only controlled by the user and can't be change programaticly. (Audio & Video Coding How-To's - How do I access the hardware volume controller?)
You can add a MPVolumeView for the user the control the global volume.

I follow the hardware changes by setting this callback
AudioSessionAddPropertyListener(kAudioSessionProperty_CurrentHardwareOutputVolume, audioVolumeChangeListenerCallback, self);
But for some reason I think I concluded that getting the initial state required a non-published API call. I can't remember at the moment. Maybe this info will get you started in the right direction!

Related

Low UILocalNotification volume for some users, any way to control it?

We have an app that uses UILocalNotification for notifying the users about events at the background.
the problem is some of the users hears the background notifications at a very low volume.
When it does happen, the only way the user can "reset" the notification volume is via a device reboot. Once that is done it comes back to a normal level.
other ways that we have tried are by changing settings outside the app:
using the volume buttons- changed the iPod's volume or the ringer volume, did not effect notifications volume level.
setting in: settings->sounds->ringer and alerts->setting to highest. did not have any effect on the notifications volume.
changing the volume at the iPod player: did not effect the notification volume.
finally restarting the iPhone - did set the notifications volume to a normal level, but it's not a good solution for the customers.
We looked for a code solution for this issue and tried many different options:
changing the iPod volume ([[MPMusicPlayerController iPodMusicPlayer]setVolume:1.0f])
only changed the iPod's volume and did not worked on notifications.
tried using [[AVAudioSession sharedInstance] setActive:YES error:NULL]; and then chaining the volume as in #1 - did not work.
using the volume slider "MPVolumeView" as is, this slider also did not seem to control notifications volume.
Is there a way that we can programmatically ensure that the notification volume is always at a normal audible level?
If not - what should we advise our users? A reboot always fixes this, but its a poor solution to advise to a user.
Thanks for your help!
It's not possible,
You can't control the notifications volume with a costume UI slider. Only the default slider provided by Apple.

Controlling the Sound of Audio

I am playing the sound in my App and sound still continue play even when App enter into background i want to control the Volume of that audio when it enter into background . Like in this APP example.I want audio volume remain maximum even user try to turn off the volume. I am unable to splve it can any one out there help me out.
if you are using AVAudioPlayer the just use AVAudioPlayer instance say player like this:
player.volume=1; //for maximum volume
This is AVAudioPlayer's volume, and in reply to your question that even if user minimizes volume of Iphone it should remain in full, then you should know that according to apple policies, there are things which have control for user only, this is what they call user privilege, your app can not control iphone volume,
and for controlling player volume (you don't need any effort if you talk about iphone volume) , i am little doubtful how you want to do this, i mean you must have some button or horizontal slider to achieve this, anyhow proceed with your logic with the delegate method
- (void)applicationDidEnterBackground:(UIApplication *)application
in your appdelegate class

A system sound ignores volume level

I am working on the game. And I have some issue with sounds.
I use system sounds to acknowledge a player, when he/she presses a button. These sounds respect the volume set by a player, when other sounds are playing (I use AVAudioPlayers and AudioQueues). But when a system sound is only to play, it ignore a volume set by player and plays at a ringer's volume.
How to force system sounds to respect a volume set by a player even when is no other sounds played?
Assuming you are meaning that players are setting the volume using the side volume buttons on the device:
I had the same problem getting SystemSound to respect the volume buttons but found a setting in "Settings"/"Sounds"/"Ringer and Alerts"/"Change With Buttons" that was "OFF" by default. Switching that to "ON" made it work.
How are your players (I assume you mean the people playing the game) setting the volume -- through the device's volume control, or through your app interface? If the latter, then this won't work, since system sounds should always play at the device volume.
According to the Multimedia Programming Guide, "Sounds play at the current system audio volume, with no programmatic volume control available."
I don't know why your system sounds would change volume when an AVAudioPlayer sound is playing. If that's the case, can you loop a silent sound with AVAudioPlayer when you're not playing other sounds? Otherwise I would try playing all sounds with AVAudioPlayer so that you have direct control over the volume.

Volume control in MPMoviePlayerController

I am trying to figure out how to adjust the volume of a movie played with MPMoviePlayerController on the iPhone without using the slider or the volume buttons on the side of the phone. Is it even possible to do this with code in a Apple approved way? I haven't been able to find anything in the APIs that relate to changing or setting the volume during movie playback.
I know a similar question was asked a little over a year ago (Is there a way to adjust volume in MPMoviePlayer Controller by program?), but I wanted to know if anyone had found a way to change the volume in MPMoviePlayerController since then.

iPhone: Adjusting playback volume in app during a phone call

I have a soundboard application that plays mp3 files using AVAudioPlayer. The sound can be adjusted to high while listening to any of the clips.
My problem is when the phone is in use and I navigate to the app to play the soundboard the volume is set very low. I'm trying to make it so the the sound from my app can be heard by the person on the other line. They can currently hear the sound but its very low and hard to make out. Is there a way to raise the volume in my app while the phone is in use?
Have you tried setting the AVAudioPlayer volume (playback gain) property to 1.0 (max)?
This could be something to do with the hardware volume settings, i.e. when you're in a call the rocker buttons on the side of the phone control the volume of the call. This volume may be controlling the volume of the app as well. May be worth increasing the volume of the call and see if this increases the volume of the app too. If so, then work for a solution to that problem such as implementing an MPVolumeView in the app and customising its behaviour.
If a phone call is answered, while your app is launched, your app is no longer running until the phone call terminates. At the end of the call you could adjust the AVAudioPlayer volume to 1.0 (100%).