Added option to resume on audio focus regain. (#624)

This commit is contained in:
Tonelico 2017-08-07 06:04:36 -07:00 committed by Mauricio Colli
parent 10c4f7b465
commit becc90409f
4 changed files with 22 additions and 1 deletions

View File

@ -47,6 +47,8 @@ import com.google.android.exoplayer2.util.Util;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import org.schabi.newpipe.R;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
@ -321,10 +323,21 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage
}
}
private boolean isResumeAfterAudioFocusGain() {
if (this.sharedPreferences == null || this.context == null) return false;
return this.sharedPreferences.getBoolean(
this.context.getString(R.string.resume_on_audio_focus_gain_key),
false
);
}
protected void onAudioFocusGain() {
if (DEBUG) Log.d(TAG, "onAudioFocusGain() called");
if (simpleExoPlayer != null) simpleExoPlayer.setVolume(DUCK_AUDIO_TO);
animateAudio(DUCK_AUDIO_TO, 1f, DUCK_DURATION);
if (isResumeAfterAudioFocusGain()) simpleExoPlayer.setPlayWhenReady(true);
}
protected void onAudioFocusLoss() {

View File

@ -14,7 +14,7 @@
<string name="autoplay_through_intent_key" translatable="false">autoplay_through_intent</string>
<string name="use_old_player_key" translatable="false">use_oldplayer</string>
<string name="player_gesture_controls_key" translatable="false">player_gesture_controls</string>
<string name="resume_on_audio_focus_gain_key" translatable="false">resume_on_audio_focus_gain</string>
<string name="default_resolution_key" translatable="false">default_resolution_preference</string>
<string name="default_resolution_value" translatable="false">360p</string>

View File

@ -71,6 +71,8 @@
<string name="player_gesture_controls_summary">Use gestures to control the brightness and volume of the player</string>
<string name="show_search_suggestions_title">Search suggestions</string>
<string name="show_search_suggestions_summary">Show suggestions when searching</string>
<string name="resume_on_audio_focus_gain_title">Resume on focus gain</string>
<string name="resume_on_audio_focus_gain_summary">Continue playing after interruptions (e.g. phone calls)</string>
<string name="download_dialog_title">Download</string>

View File

@ -64,6 +64,12 @@
android:summary="@string/player_gesture_controls_summary"
android:title="@string/player_gesture_controls_title"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/resume_on_audio_focus_gain_key"
android:summary="@string/resume_on_audio_focus_gain_summary"
android:title="@string/resume_on_audio_focus_gain_title"/>
</PreferenceCategory>
<PreferenceCategory