Merge branch 'pause-on-interrupt' of git://github.com/TomHennen/AntennaPod into TomHennen-pause-on-interrupt

This commit is contained in:
daniel oeh 2013-10-03 13:15:47 +02:00
commit 088878fcfd
5 changed files with 34 additions and 8 deletions

View File

@ -309,6 +309,8 @@
<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_pausePlaybackForFocusLoss_sum">Pause playback instead of lowering volume when another app wants to play sounds</string>
<string name="pref_pausePlaybackForFocusLoss_title">Pause for interruptions</string>
<!-- Online feed view -->
<string name="subscribe_label">Subscribe</string>

View File

@ -31,6 +31,13 @@
android:key="prefPlaybackSpeedLauncher"
android:summary="@string/pref_playback_speed_sum"
android:title="@string/pref_playback_speed_title" />
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
android:key="prefPauseForFocusLoss"
android:summary="@string/pref_pausePlaybackForFocusLoss_sum"
android:title="@string/pref_pausePlaybackForFocusLoss_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/network_pref">
<ListPreference

View File

@ -48,6 +48,7 @@ public class UserPreferences implements
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
@ -69,6 +70,7 @@ public class UserPreferences implements
private int episodeCacheSize;
private String playbackSpeed;
private String[] playbackSpeedArray;
private boolean pauseForFocusLoss;
private UserPreferences(Context context) {
this.context = context;
@ -121,6 +123,7 @@ public class UserPreferences implements
playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
PREF_PLAYBACK_SPEED_ARRAY, null));
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
}
private int readThemeValue(String valueFromPrefs) {
@ -265,6 +268,11 @@ public class UserPreferences implements
return instance.enableAutodownload;
}
public static boolean shouldPauseForFocusLoss() {
instanceAvailable();
return instance.pauseForFocusLoss;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
if (AppConfig.DEBUG)
@ -309,6 +317,8 @@ public class UserPreferences implements
} else if (key.equals(PREF_PLAYBACK_SPEED_ARRAY)) {
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
PREF_PLAYBACK_SPEED_ARRAY, null));
} else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS)) {
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
}
}

View File

@ -381,11 +381,18 @@ public class PlaybackService extends Service {
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
if (status == PlayerStatus.PLAYING) {
if (!UserPreferences.shouldPauseForFocusLoss()) {
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:

@ -1 +1 @@
Subproject commit 643cc2a1afd4f849d5a33f014f877f7d7c10b2db
Subproject commit c56bf97269d5dc90df1c428fd18df0e7619eff0e