From e980a7656c55a5ecb14e47ee9efa98492a570a97 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sat, 20 Feb 2016 14:15:02 +0100 Subject: [PATCH] Duck and unduck done right --- .../playback/PlaybackServiceMediaPlayer.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java index a82e82506..20bdd1f75 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java @@ -693,7 +693,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre } /** - * Sets the playback speed. + * Sets the playback volume. * This method is executed on an internal executor service. */ public void setVolume(final float volumeLeft, float volumeRight) { @@ -701,7 +701,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre } /** - * Sets the playback speed. + * Sets the playback volume. * This method is executed on the caller's thread. */ private void setVolumeSync(float volumeLeft, float volumeRight) { @@ -946,15 +946,16 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre if (pausedBecauseOfTransientAudiofocusLoss) { // we paused => play now resume(); } else { // we ducked => raise audio level back - audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, - AudioManager.ADJUST_RAISE, 0); + setVolumeSync(UserPreferences.getLeftVolume(), + UserPreferences.getRightVolume()); } } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { if (playerStatus == PlayerStatus.PLAYING) { if (!UserPreferences.shouldPauseForFocusLoss()) { Log.d(TAG, "Lost audio focus temporarily. Ducking..."); - audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, - AudioManager.ADJUST_LOWER, 0); + final float DUCK_FACTOR = 0.25f; + setVolumeSync(DUCK_FACTOR * UserPreferences.getLeftVolume(), + DUCK_FACTOR * UserPreferences.getRightVolume()); pausedBecauseOfTransientAudiofocusLoss = false; } else { Log.d(TAG, "Lost audio focus temporarily. Could duck, but won't, pausing...");