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.
This commit is contained in:
parent
6b69f7fe28
commit
3f8e6c26a3
|
@ -250,5 +250,7 @@
|
|||
<string name="folder_not_empty_dialog_title">Folder is not empty</string>
|
||||
<string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other files will be placed directly in this folder. Continue anyway?</string>
|
||||
<string name="set_to_default_folder">Choose default folder</string>
|
||||
<string name="pref_pausePlaybackForNotifications_sum">Pause playback instead of lowering volume when another app wants to play sounds</string>
|
||||
<string name="pref_pausePlaybackForNotifications_title">Pause for notifications</string>
|
||||
|
||||
</resources>
|
|
@ -17,7 +17,12 @@
|
|||
android:key="prefFollowQueue"
|
||||
android:summary="@string/pref_followQueue_sum"
|
||||
android:title="@string/pref_followQueue_title" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
android:key="prefPauseForNotifications"
|
||||
android:summary="@string/pref_pausePlaybackForNotifications_sum"
|
||||
android:title="@string/pref_pausePlaybackForNotifications_title" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/network_pref" >
|
||||
<ListPreference
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue