A system sound ignores volume level - iphone

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.

Related

In Unity: Volume does not adjust while game is paused via timescale being stopped / equal to 0

I have a settings menu in my game, where I have different audio (background music, dialogue, etc) where I can adjust the volume manually.
This happens during pause, so you can hear the volume and set it to your preference.
This was working fine, then one day, it stopped, and I haven't been able to figure out why.
All I know is that the volume of the audioSource DOES update, but the "actual" audio stays the same volume "until" you unpause (set the timescale back to 1) then it changes to match what the variable in the AudioSource says.
To emphasise, the value "does" update, but the real sound stays the same until you unpause. How can I hear the sound change while the game is paused?
The fact this seemed to work before, suggests an update or change in setting may have broken it, but may also be able to fix it? Otherwise I just have to not use timescale for pausing, or move the volume control settings outside of the pause mechanics
Thanks in advance
This may be caused by the audio mixers updateMode being set to AudioMixerUpdateMode.Normal.
Changing the updateMode to AudioMixerUpdateMode.UnscaledTime will ignore Time.timeScale and update the audio mixer in real time.

iPod Volume Level Affects App Volume Level

I am writing an iPad app that uses the "Flite" text-to-speech engine to announce specific events. The Flite engine uses an AVAudioPlayer instance to play the speech audio once it renders. For fun, I decided to add some simple controls to my app to allow the user to control iPod playback (next, prev, play/pause and volume - the basics) while my app is running using MPMusicPlayerController (of course).
The problem I am having is that when I adjust the iPod volume using MPMusicPlayerController, all of my audio is affected, including other sound effects and the speech audio. I set the volume for these other audio players (AVAudioPlayer instances) to 1.0 before playing the sound but it seems that the volume is always capped at whatever the iPod player volume is set to...
Is this normal? And what can I do to get around it? I want my app's audio to play at system full volume regardless of the volume level of the iPod player. (Example: The user had set the system volume to 80% of the device's max. I want my app to play audio at 100% of that 80% while allowing the user to adjust the iPod audio playback to 0-100% of that 80%.) Note: I am not interested in "ducking" but setting the iPod volume lower at all times while my app is running (background music).
I also have the problem, that -sometimes- when you first launch the app and press play on the iPod player (which sends the [player play] call), the iPod does not respond. If I press the home button, go into the iPod app and start playback then, once returning to my app, it works fine. What the deal with that?
Thanks in advance for any help!!
It could be something to do with the audio session category you've specified. Check out the Audio Session Programming Guide to see if you've chosen the right category.
The volume buttons on the side control the system volume and by extension the volume of your app's sounds.
I guess it's considered to be the Master volume control.
you can set the volume for specific samples or sounds using the AVItem's setVolume
[item setVolume]
You can create an AVItem to reference an existing sound file in your application or on the iphone. The code is pretty simple and looks like this -->
AVItem *item [[AVItem alloc]
initWithPath:#"the file"];
[item setVolume];
btw, this will not affect the rest of the audio channel (instantiated by some kinda AVController object) and the volume that you've set in your code will not be displayed on you screen so im not sure if you can change it at run time.

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%).

Is it OK to mix AudioServicesPlaySystemSound and AVAudioPlayer?

We have a game that is very close to being released, but we have one extremely annoying problem. One on of our Beta testers phones, he can't hear any of the in game sound effects. He can, however, hear the background music and the title screen music just fine.
The background and title music are both being played via AVAudioPlayer (they are longer, we need looping and volume control, etc). The sound effects are simply being played with AudioServicesPlaySystemSound (they are very short, we don't need precise control or to know when they end, etc). This works on most iPhones, but not on this one. All of this is being played with an audio session of AVAudioSessionCategorySoloAmbient.
So I have two questions:
- First, is this an acceptable implementation? i.e. is there something I missed that says you can't mix these two frameworks, or a reason why its a bad idea to mix them?
- Second, has anyone seen something like this before? If so, did you find a way around it?
Additional background note: I can pretty conclusively say that on his phone, it is the mixing of the two frameworks. He was able to hear sounds until roughly the same build where we added the title screen music. Also, if I change one of the sounds to work through an AVAudioPlayer, he's able to hear it. Unfortunately, I can't simply move the sounds into AVAudioPlayers because it just doesn't perform well at all, and I need better synchronization.
EDIT 2:
I've determined the cause of the error. The two different audio frameworks play on two different volume settings. There is the main volume (that's what shows up once you are in the app, and has no title on it) and the ringer volume (that's what shows up when you're on the home screen without any app loaded). The AVAudioPlayer calls play with the main volume setting. As I have set the category to AVAudioSessionCategorySoloAmbient (see code below), this is the volume control that will be adjusted if you use the volume rocker inside the app. The SystemSounds, however, are played at the Ringer Volume. This will NOT come up inside the app, and as such does not allow the user to adjust their settings during the game.
It's easy to see the possible confusion for the user: Let's say they have their ringer set to low, or even off. They start playing the game. They hear the title screen music (AVAudioPlayer) and are able to turn the volume up or down and it responds normally. Then they start the game and the sound effects play (SystemSounds), and they hear nothing because the ringer volume is low/off. In an effort to hear the sound effects, they bump up the volume and the background music responds accordingly. So from this point of view, it definitely looks like the sound effects just aren't playing.
If you have this similar situation, have your user make sure that their ringer volume is up before playing the game and their mute switch is on (i.e. not muted). You can also verify all of this by doing the test yourself - drop your ringer volume and bump your in-app volume up. Your SystemSounds should drop out of the mix.
Original answer:
In re-digging through all of the docs, I found the answer. I wasn't properly activating the audio session. Previously I only had this code to set the category:
NSError *setCategoryError = nil;
BOOL categoryWasSet = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategorySoloAmbient
error: &setCategoryError];
But I needed to also add the following code to explicitly activate the audio session:
NSError *activationError = nil;
BOOL activationSuccess = [[AVAudioSession sharedInstance]
setActive: YES
error: &activationError];
I've re-tested with this user, and it has completely fixed the issue. Hope that helps anyone who might have a similar problem.
EDIT: This doesn't seem to have resolved the issue after all. I got a false positive from my tester, and when examined more in detail it seems that he didn't actually hear the SystemSound generated sounds.
I have two apps on the app store that mix those two frameworks. AVAudioPlayer for sounds that require start and stop and volume control and AudioServices toolbox for short little beeps and clicks. The only think I can think of, off the top of my head, is that the volume of AVAudioPlayer seems to be controlled separately from the AudioServices sounds. So check to make sure that the tester doesn't have sounds turned off (with the vibrate mode switch) or the volume turned way down.
If this doesn't help, tell me more about your sounds/code and I can add some code to my app to see if I can get the same behavior. Of course, sounds like most your testers don't have this problem, and I probably won't see it either.

iPhone (SDK 2.2): adusting playback volume while NOT actively playing music w/ AVFoundation?

So I have an app which plays many short sound clips. I need to know when the sounds are finished playing, and I need to use mp3s, so I'm using AVFoundation for the sound playback.
When a sound is actively playing, and the user uses the hardware volume buttons, the playback volume changes. Problem is, the app is NOT constantly playing sounds, and when it's not, and the hardware buttons are used, the RINGER volume gets adjusted instead.
How do I set it up so, as long as the app is running, the user can adjust the playback volume?
Thanks!
Turns out this can be accomplished by allocating an AVAudioPlayer with any valid sound file and calling the prepareToPlay method, without ever calling the play method.
Works perfectly.
Start an AudioSession and don't stop it when you're not playing sounds.
so you want to disable ringer playback volume as long as the app is running? therefore the hardware controls will only adjust the app playback sounds?
i dont think this is possible unless you are "always playing sound" for example, many games are always playing background music or what have you.
You might be able to accomplish this by constantly playing a 0 volume sound as long as your app is running. You could then play your sound clips over it.
How do I play multiple sounds simultaneously?