From 3f8e6c26a348562799762ae1289195e557a02eaa Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Wed, 14 Aug 2013 12:26:03 -0400 Subject: Adds an option to pause audio while audio focus is lost. This is helpful when using navigation apps (for example) so that you can hear what the navigation app says and you don't miss whatever was being said on your podcast. Without this setting checked they may wind up talking over each other, which can be confusing. --- .../danoeh/antennapod/preferences/UserPreferences.java | 10 ++++++++++ src/de/danoeh/antennapod/service/PlaybackService.java | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index f2f35f41d..662db9b17 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -41,6 +41,7 @@ public class UserPreferences implements public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; + public static final String PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS = "prefPauseForNotifications"; private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; @@ -60,6 +61,7 @@ public class UserPreferences implements private boolean enableAutodownloadWifiFilter; private String[] autodownloadSelectedNetworks; private int episodeCacheSize; + private boolean pauseForNotifications; private UserPreferences(Context context) { this.context = context; @@ -108,6 +110,7 @@ public class UserPreferences implements episodeCacheSize = readEpisodeCacheSize(sp.getString( PREF_EPISODE_CACHE_SIZE, "20")); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); + pauseForNotifications = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS, false); } private int readThemeValue(String valueFromPrefs) { @@ -210,6 +213,11 @@ public class UserPreferences implements instanceAvailable(); return instance.enableAutodownload; } + + public static boolean shouldPauseForNotifications() { + instanceAvailable(); + return instance.pauseForNotifications; + } @Override public void onSharedPreferenceChanged(SharedPreferences sp, String key) { @@ -250,6 +258,8 @@ public class UserPreferences implements PREF_EPISODE_CACHE_SIZE, "20")); } else if (key.equals(PREF_ENABLE_AUTODL)) { enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); + } else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS)) { + pauseForNotifications = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS, false); } } diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 7c306984c..5e0f6b46e 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -353,11 +353,18 @@ public class PlaybackService extends Service { break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: if (status == PlayerStatus.PLAYING) { - if (AppConfig.DEBUG) - Log.d(TAG, "Lost audio focus temporarily. Ducking..."); - audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, - AudioManager.ADJUST_LOWER, 0); - pausedBecauseOfTransientAudiofocusLoss = true; + if (!UserPreferences.shouldPauseForNotifications()) { + if (AppConfig.DEBUG) + Log.d(TAG, "Lost audio focus temporarily. Ducking..."); + audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, + AudioManager.ADJUST_LOWER, 0); + pausedBecauseOfTransientAudiofocusLoss = true; + } else { + if (AppConfig.DEBUG) + Log.d(TAG, "Lost audio focus temporarily. Could duck, but won't, pausing..."); + pause(false, false); + pausedBecauseOfTransientAudiofocusLoss = true; + } } break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: -- cgit v1.2.3 From bd4c365c1147a214d20d33a6c2989b247452a732 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Wed, 14 Aug 2013 12:47:04 -0400 Subject: updated name of the preference to use 'FocusLoss' rather than 'Notifications' to more accurately reflect what it does --- src/de/danoeh/antennapod/preferences/UserPreferences.java | 14 +++++++------- src/de/danoeh/antennapod/service/PlaybackService.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 662db9b17..a7df27ddc 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -41,7 +41,7 @@ public class UserPreferences implements public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; - public static final String PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS = "prefPauseForNotifications"; + public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss"; private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; @@ -61,7 +61,7 @@ public class UserPreferences implements private boolean enableAutodownloadWifiFilter; private String[] autodownloadSelectedNetworks; private int episodeCacheSize; - private boolean pauseForNotifications; + private boolean pauseForFocusLoss; private UserPreferences(Context context) { this.context = context; @@ -110,7 +110,7 @@ public class UserPreferences implements episodeCacheSize = readEpisodeCacheSize(sp.getString( PREF_EPISODE_CACHE_SIZE, "20")); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); - pauseForNotifications = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS, false); + pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); } private int readThemeValue(String valueFromPrefs) { @@ -214,9 +214,9 @@ public class UserPreferences implements return instance.enableAutodownload; } - public static boolean shouldPauseForNotifications() { + public static boolean shouldPauseForFocusLoss() { instanceAvailable(); - return instance.pauseForNotifications; + return instance.pauseForFocusLoss; } @Override @@ -258,8 +258,8 @@ public class UserPreferences implements PREF_EPISODE_CACHE_SIZE, "20")); } else if (key.equals(PREF_ENABLE_AUTODL)) { enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); - } else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS)) { - pauseForNotifications = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_NOTIFICATIONS, false); + } else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS)) { + pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); } } diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 5e0f6b46e..d04046223 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -353,7 +353,7 @@ public class PlaybackService extends Service { break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: if (status == PlayerStatus.PLAYING) { - if (!UserPreferences.shouldPauseForNotifications()) { + if (!UserPreferences.shouldPauseForFocusLoss()) { if (AppConfig.DEBUG) Log.d(TAG, "Lost audio focus temporarily. Ducking..."); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, -- cgit v1.2.3