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.
Related
I work on a VOIP app.
I use Core Audio Audio Units for playing and recording audio. I need to be able to manipulate sound volume and output devices. I am trying to use MPVolumeView to set sound volume and choose output devices.
My problem is: When I start using(start playout and capture for RemoteIO Audio Unit) Audio Units it seems MPVolumeView no longer control volume of my session but instead it controls system wide sound preferences. At the same time hardware buttons control volume of sounds played by Audio Units. Also when I start using Audio Units MPVolumeView start showing button to change output devices but before that it doesn't.
It seems that MPVolumeView controls sound volume for some system wide audio session but when I start using Audio Units another app wide (or even Audio Unit wide) audio session is created and used to play sound.
So the question is how to make MPVolumeView control sound volume for my Core Audio audio session?
I would appreciate any hints on why this happens. I've spent almost all day googling and I see that some people have related problems but none got any hints :(. I can also post more details if needed.
Confirmed as a bug by Apple engineer.
In more details - MPVolumeView should be tied to a specific audio route (in more broad sense, like audio route + audio category + mode etc.), and it is for a couple of most common routes (e.g. headphones + play category + default mode) but not to all custom routes you can create.
So basically when one creates some custom route MPVolumeView still tries to control it's last (workable) or default route.
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
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.
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%).
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?