Skip to content

Commit 9903e26

Browse files
author
Eric Laurent
committed
Volume keys control music volume after music stops
On phones, add a short delay during which volume keys still control music volume after music has stopped. This is similar to the tablet behavior for notifications volume. It allows users to control the prompt volume for talk back, voice search or navigation even after the prompt has stopped. Bug 7162364. Change-Id: Iffbca9ec30ebcbe5846f783ddd260b6e736caf2b
1 parent f98db0d commit 9903e26

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

media/java/android/media/AudioService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ public void onError(int error) {
387387
private Looper mSoundPoolLooper = null;
388388
// volume applied to sound played with playSoundEffect()
389389
private static int sSoundEffectVolumeDb;
390-
// getActiveStreamType() will return STREAM_NOTIFICATION during this period after a notification
390+
// getActiveStreamType() will return:
391+
// - STREAM_NOTIFICATION on tablets during this period after a notification stopped
392+
// - STREAM_MUSIC on phones during this period after music or talkback/voice search prompt
391393
// stopped
392-
private static final int NOTIFICATION_VOLUME_DELAY_MS = 5000;
394+
private static final int DEFAULT_STREAM_TYPE_OVERRIDE_DELAY_MS = 5000;
393395
// previous volume adjustment direction received by checkForRingerModeChange()
394396
private int mPrevVolDirection = AudioManager.ADJUST_SAME;
395397
// Keyguard manager proxy
@@ -2340,7 +2342,8 @@ private int getActiveStreamType(int suggestedStreamType) {
23402342
if (DEBUG_VOL)
23412343
Log.v(TAG, "getActiveStreamType: Forcing STREAM_REMOTE_MUSIC");
23422344
return STREAM_REMOTE_MUSIC;
2343-
} else if (AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)) {
2345+
} else if (AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC,
2346+
DEFAULT_STREAM_TYPE_OVERRIDE_DELAY_MS)) {
23442347
if (DEBUG_VOL)
23452348
Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC stream active");
23462349
return AudioSystem.STREAM_MUSIC;
@@ -2369,9 +2372,9 @@ private int getActiveStreamType(int suggestedStreamType) {
23692372
return AudioSystem.STREAM_VOICE_CALL;
23702373
}
23712374
} else if (AudioSystem.isStreamActive(AudioSystem.STREAM_NOTIFICATION,
2372-
NOTIFICATION_VOLUME_DELAY_MS) ||
2375+
DEFAULT_STREAM_TYPE_OVERRIDE_DELAY_MS) ||
23732376
AudioSystem.isStreamActive(AudioSystem.STREAM_RING,
2374-
NOTIFICATION_VOLUME_DELAY_MS)) {
2377+
DEFAULT_STREAM_TYPE_OVERRIDE_DELAY_MS)) {
23752378
if (DEBUG_VOL) Log.v(TAG, "getActiveStreamType: Forcing STREAM_NOTIFICATION");
23762379
return AudioSystem.STREAM_NOTIFICATION;
23772380
} else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {

0 commit comments

Comments
 (0)