IPod volume affects application volume

I am writing an iPad application that uses the Flite text-to-speech engine to announce specific events. The Flite engine uses an instance of AVAudioPlayer to play speech sound after it is created. For fun, I decided to add some simple controls to the application to allow the user to control the playback of the iPod (hereinafter, the previous, play / pause and volume are the basics), while my application works using MPMusicPlayerController (of course).

The problem I am having is that when I adjust the volume of the iPod using MPMusicPlayerController, all my sounds are affected, including other sound effects and speech sound. I set the volume for these other audio players (instances of AVAudioPlayer) to 1.0 before playing the sound, but it seems that the volume is always limited to what is set for the iPod speaker ...

This is normal? And what can I do to get around this? I want the sound of my application to play at the system level, regardless of the volume level of the iPod. (Example: a user has set the system volume to 80% of the maximum number of devices. I want my application to play audio at 100% of this 80%, allowing the user to set iPod audio playback to 0-100% of this 80%.) Note. I'm not interested in "dodging", but it also reduces the volume of the iPod while my application is running (background music).

I also have a problem: sometimes, when you first start the application and press the play button on the iPod (which sends a call [play play]), the iPod does not respond. If I press the home button, go to the iPod application and start playing, and then, returning to my application, it works fine. What is the reason for this?

Thanks in advance for your help!

+8
iphone ipad ipod avaudioplayer mpmusicplayercontroller
source share
3 answers

This may be due to the category of audio sessions you have specified. Check out our Audio Programming Guide to see if you have selected the appropriate category.

+1
source share

The volume buttons on the side panel adjust the volume of the system and, as a rule, the volume of your application sounds.

I assume that it is considered the main volume control.

0
source share

You can set the volume for specific samples or sounds using AVItem setVolume

[item setVolume]

You can create AVItem to link to an existing sound file in an application or on an iphone. The code is pretty simple and looks like this:>

AVItem * item [[AVItem alloc] initWithPath: @ "file"]; [item setVolume];

btw, this will not affect the rest of the audio channel (created by a separate AVController object), and the one you set in your code will not be displayed on your screen, so I'm not sure if you can change it at runtime.

0
source share

Source: https://habr.com/ru/post/651065/


All Articles