Optionally resume playback after call.

Defaults to true.

fixes AntennaPod/AntennaPod#753
This commit is contained in:
Tom Hennen 2015-05-03 15:16:47 -04:00
parent cd4bd0e37d
commit db0ce285a3
4 changed files with 21 additions and 3 deletions

View File

@ -81,6 +81,12 @@
android:key="prefPauseForFocusLoss"
android:summary="@string/pref_pausePlaybackForFocusLoss_sum"
android:title="@string/pref_pausePlaybackForFocusLoss_title" />
<CheckBoxPreference
android:defaultValue="true"
android:enabled="true"
android:key="prefResumeAfterCall"
android:summary="@string/pref_resumeAfterCall_sum"
android:title="@string/pref_resumeAfterCall_title"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/network_pref">

View File

@ -60,6 +60,7 @@ public class UserPreferences implements
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";
public static final String PREF_RESUME_AFTER_CALL = "prefResumeAfterCall";
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
private static final String PREF_REWIND_SECS = "prefRewindSecs";
private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
@ -98,6 +99,7 @@ public class UserPreferences implements
private String playbackSpeed;
private String[] playbackSpeedArray;
private boolean pauseForFocusLoss;
private boolean resumeAfterCall;
private int fastForwardSecs;
private int rewindSecs;
private boolean isFreshInstall;
@ -164,6 +166,7 @@ public class UserPreferences implements
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
PREF_PLAYBACK_SPEED_ARRAY, null));
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
resumeAfterCall = sp.getBoolean(PREF_RESUME_AFTER_CALL, true);
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
@ -393,6 +396,11 @@ public class UserPreferences implements
return instance.pauseForFocusLoss;
}
public static boolean shouldResumeAfterCall() {
instanceAvailable();;
return instance.resumeAfterCall;
}
public static boolean isFreshInstall() {
instanceAvailable();
return instance.isFreshInstall;
@ -454,6 +462,8 @@ public class UserPreferences implements
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);
} else if (key.equals(PREF_RESUME_AFTER_CALL)) {
resumeAfterCall = sp.getBoolean(PREF_RESUME_AFTER_CALL, false);
} else if (key.equals(PREF_FAST_FORWARD_SECS)) {
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
} else if (key.equals(PREF_REWIND_SECS)) {

View File

@ -40,7 +40,7 @@ import de.danoeh.antennapod.core.util.playback.VideoPlayer;
* Manages the MediaPlayer object of the PlaybackService.
*/
public class PlaybackServiceMediaPlayer {
public static final String TAG = "PlaybackServiceMediaPlayer";
public static final String TAG = "PlaybackSvcMediaPlayer";
/**
* Return value of some PSMP methods if the method call failed.
@ -799,10 +799,10 @@ public class PlaybackServiceMediaPlayer {
// If there is an incoming call, playback should be paused permanently
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final int callState = (tm != null) ? tm.getCallState() : 0;
Log.d(TAG, "Call state: " + callState);
Log.i(TAG, "Call state:" + callState);
if (focusChange == AudioManager.AUDIOFOCUS_LOSS || callState != TelephonyManager.CALL_STATE_IDLE) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS ||
(!UserPreferences.shouldResumeAfterCall() && callState != TelephonyManager.CALL_STATE_IDLE)) {
Log.d(TAG, "Lost audio focus");
pause(true, false);
callback.shouldStop();

View File

@ -379,6 +379,8 @@
<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>
<string name="pref_resumeAfterCall_sum">Resume playback after a phone call completes</string>
<string name="pref_resumeAfterCall_title">Resume after call</string>
<!-- Online feed view -->
<string name="subscribe_label">Subscribe</string>