Hardware volume buttons and OpenSL ES

462 views
Skip to first unread message

sjmerel

unread,
Jul 27, 2014, 6:09:58 AM7/27/14
to andro...@googlegroups.com
I have a native library that plays audio using OpenSL ES.  I've noticed that when an app that is using this library is active, the hardware volume buttons change the media volume, which is what I would expect.  However, when I return to the home screen from that app, the first time I use the volume buttons, they still affect the media volume, not the ringer volume as I would expect.  If I let the volume overlay disappear by waiting a few seconds and press the volume buttons again, they now affect the ringer volume.

The app itself is a pretty thin layer around the native library, and is not calling any other audio-specific code.  I experimented with calling setVolumeControlStream() from the Java code, but that seemed to have no effect.

Is this behavior of the hardware volume buttons being controlled by OpenSL ES?  Is there any way I can control it myself?  Is this behavior in the home screen a bug in Android or OpenSL? I'm running Android 4.4.4.

thanks
-steve

s061...@gmail.com

unread,
Jul 27, 2014, 10:08:57 PM7/27/14
to andro...@googlegroups.com
I have the same problem on Android 4.2.1 (Galaxy Nexus).

2014年7月27日日曜日 19時09分58秒 UTC+9 sjmerel:

Glenn Kasten

unread,
Jul 28, 2014, 10:11:18 AM7/28/14
to andro...@googlegroups.com
I'm pretty sure this is generic behavior for any of the audio playback APIs,
not just OpenSL ES.  To confirm, please try it with android.media.AudioTrack
and stream type STREAM_MUSIC (which is what OpenSL ES defaults to).
You can change the stream type in both android.media.AudioTrack and
OpenSL ES.  For the latter, see section "Android configuration interface"
of <NDK>/docs/opensles/index.html

By the way, the details of the behavior of the volume keys is something that changes
fairly often in Android. The user interface designers have tried
several different approaches to volume management, looking for the perfect
balance of ease of use vs flexibility for power users.
It is actually a surprisingly difficult topic, far more complex
than one might imagine.

sjmerel

unread,
Aug 6, 2014, 2:13:03 AM8/6/14
to andro...@googlegroups.com
Hi Glenn,

The Google Play Music app doesn't behave this way... when I use the volume buttons from within the Play Music app, they control the media volume, and when I return to the home screen, they immediately control the ringer volume.  This is the behavior I would expect.

What I find on my apps is that after I return to the home screen, the buttons will continue to control the media volume for a while, and will eventually return to controlling the ringer volume.  (Occasionally they never return to controlling the ringer volume, though I haven't been able to reproduce this reliably.)

Do you know how the Play Music app, or other apps, are achieving this?

thanks!
-steve

Athos | n-Track

unread,
Aug 6, 2014, 7:47:42 AM8/6/14
to andro...@googlegroups.com
hi steve,

have you tried managing the audio focus?
http://developer.android.com/training/managing-audio/audio-focus.html

athos

Athos Bacchiocchi
n-Track Development Team
_______________________

n-Track Audio Software
Follow n-Track on Facebook
_______________________


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

Glenn Kasten

unread,
Aug 6, 2014, 6:59:28 PM8/6/14
to andro...@googlegroups.com
A colleague suggests:

The default volume control is based on the last 5s of stream activity, so if you played on STREAM_MUSIC "recently", after going to the home screen, you will still control the media volume.
Is it also possible that your library is still playing (silence?) while the user is on the home screen?
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

sjmerel

unread,
Aug 18, 2014, 12:05:52 PM8/18/14
to andro...@googlegroups.com
Yes - that explains the behavior I was seeing, and it turns out that the user who said the buttons were not controlling the ringer volume even after 5 seconds had gone by was not properly suspending the audio output.

thanks!
-steve
A colleague suggests:

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages