8

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!!

T.Rob
  • 31,522
  • 9
  • 59
  • 103
Vic320
  • 1,105
  • 2
  • 10
  • 22
  • Hi Vic, Did you got the solution for this since I am also facing the same issue with MPMusicPlayerController & AVAudioPlayer . – Ajay Sharma Mar 19 '11 at 18:24
  • No, I did implement "ducking" but this solution is not the behavior that I or my users what... – Vic320 Apr 08 '11 at 14:30

3 Answers3

1

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.

jdmunro
  • 581
  • 2
  • 10
0

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.

koregan
  • 10,054
  • 4
  • 23
  • 36
  • I am not trying to override the side button volume control. I am trying to lower the iPod app's volume relative to my app's volume. However, when I lower the iPod app's volume it also lower's my app's volume. All volume levels are at or lower then the master volume set by the buttons. – Vic320 Apr 08 '11 at 14:25
0

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.

luca590
  • 460
  • 2
  • 5
  • 25
  • This does not work. Even if I set the volume to 100% (1.0) it still is never any higher than what the iPod app's volume is set to. I do not see why the iPod volume setting should affect my app's volume. Of course, I do expect my app's volume not to exceed the master volume level. I wonder if Apple makes the master volume the same as the iPod volume... – Vic320 Apr 08 '11 at 14:28
  • Are you using an AVAudioPlayer? – luca590 Apr 08 '11 at 15:02
  • if not you might want to consider it. Because thats in the same API as the [setVolume] so will probably work much better – luca590 Apr 08 '11 at 17:03
  • Yes, all of the audio played by my application use AVAudio Player. Again, I set the volume of the my AVAudioPlayer instance to 1.0 before I play the sound but it always plays the audio at whatever the volume level is set to on the iPod app. – Vic320 Apr 11 '11 at 16:03
  • ok, thats interesting. I have an application in which I use the [setVolume:...] method and it works for mine, but if you do fix it or simply find out it cant be done please post the link. Sorry I wasnt able to fix it. – luca590 Apr 11 '11 at 16:10