Merge pull request #5740 from ByteHamster/upon-exiting-video

Make it easier to play only audio, not video
This commit is contained in:
ByteHamster 2022-02-22 19:54:05 +01:00 committed by GitHub
commit 2f3efa5d33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 71 deletions

View File

@ -91,6 +91,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
private PlaybackController controller;
private boolean showTimeLeft = false;
private boolean isFavorite = false;
private boolean switchToAudioOnly = false;
private Disposable disposable;
private float prog;
@ -119,6 +120,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
protected void onResume() {
super.onResume();
StorageUtils.checkStorageAvailability(this);
switchToAudioOnly = false;
if (PlaybackService.isCasting()) {
Intent intent = PlaybackService.getPlayerActivityIntent(this);
if (!intent.getComponent().getClassName().equals(VideoplayerActivity.class.getName())) {
@ -149,8 +151,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
@Override
public void onUserLeaveHint() {
if (!PictureInPictureUtil.isInPictureInPictureMode(this) && UserPreferences.getVideoBackgroundBehavior()
== UserPreferences.VideoBackgroundBehavior.PICTURE_IN_PICTURE) {
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
compatEnterPictureInPicture();
}
}
@ -480,9 +481,7 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(TAG, "Videosurface was destroyed");
videoSurfaceCreated = false;
if (controller != null && !destroyingDueToReload
&& UserPreferences.getVideoBackgroundBehavior()
!= UserPreferences.VideoBackgroundBehavior.CONTINUE_PLAYING) {
if (controller != null && !destroyingDueToReload && !switchToAudioOnly) {
controller.notifyVideoSurfaceAbandoned();
}
}
@ -590,17 +589,16 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
menu.findItem(R.id.set_sleeptimer_item).setVisible(!controller.sleepTimerActive());
menu.findItem(R.id.disable_sleeptimer_item).setVisible(controller.sleepTimerActive());
if (PictureInPictureUtil.supportsPictureInPicture(this)) {
menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true);
}
menu.findItem(R.id.player_switch_to_audio_only).setVisible(true);
menu.findItem(R.id.audio_controls).setIcon(R.drawable.ic_sliders);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.player_go_to_picture_in_picture) {
compatEnterPictureInPicture();
if (item.getItemId() == R.id.player_switch_to_audio_only) {
switchToAudioOnly = true;
finish();
return true;
}
if (item.getItemId() == android.R.id.home) {

View File

@ -13,7 +13,6 @@ import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.core.preferences.UsageStatistics;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import java.util.Map;
@ -54,11 +53,6 @@ public class PlaybackPreferencesFragment extends PreferenceFragmentCompat {
SkipPreferenceDialog.showSkipPreference(activity, SkipPreferenceDialog.SkipDirection.SKIP_FORWARD, null);
return true;
});
if (!PictureInPictureUtil.supportsPictureInPicture(activity)) {
ListPreference behaviour = findPreference(UserPreferences.PREF_VIDEO_BEHAVIOR);
behaviour.setEntries(R.array.video_background_behavior_options_without_pip);
behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip);
}
findPreference(PREF_PLAYBACK_PREFER_STREAMING).setOnPreferenceChangeListener((preference, newValue) -> {
// Update all visible lists to reflect new streaming action button
EventBus.getDefault().post(new UnreadItemsUpdateEvent());

View File

@ -90,9 +90,6 @@ public class PreferenceUpgrader {
UserPreferences.setEnqueueLocation(enqueueLocation);
}
}
if (oldVersion < 1080100) {
prefs.edit().putString(UserPreferences.PREF_VIDEO_BEHAVIOR, "pip").apply();
}
if (oldVersion < 2010300) {
// Migrate hardware button preferences
if (prefs.getBoolean("prefHardwareForwardButtonSkips", false)) {

View File

@ -52,10 +52,10 @@
</item>
<item
android:id="@+id/player_go_to_picture_in_picture"
custom:showAsAction="collapseActionView"
android:title="@string/player_go_to_picture_in_picture"
android:visible="false">
android:id="@+id/player_switch_to_audio_only"
custom:showAsAction="collapseActionView"
android:title="@string/player_switch_to_audio_only"
android:visible="false">
</item>
<item

View File

@ -34,13 +34,6 @@
android:key="prefResumeAfterCall"
android:summary="@string/pref_resumeAfterCall_sum"
android:title="@string/pref_resumeAfterCall_title"/>
<ListPreference
android:defaultValue="pip"
android:entries="@array/video_background_behavior_options"
android:entryValues="@array/video_background_behavior_values"
android:key="prefVideoBehavior"
android:summary="@string/pref_videoBehavior_sum"
android:title="@string/pref_videoBehavior_title"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/playback_control">

View File

@ -87,7 +87,6 @@ public class UserPreferences {
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
private static final String PREF_RESUME_AFTER_CALL = "prefResumeAfterCall";
public static final String PREF_VIDEO_BEHAVIOR = "prefVideoBehavior";
private static final String PREF_TIME_RESPECTS_SPEED = "prefPlaybackTimeRespectsSpeed";
public static final String PREF_STREAM_OVER_DOWNLOAD = "prefStreamOverDownload";
@ -846,15 +845,6 @@ public class UserPreferences {
.apply();
}
public static VideoBackgroundBehavior getVideoBackgroundBehavior() {
switch (prefs.getString(PREF_VIDEO_BEHAVIOR, "pip")) {
case "stop": return VideoBackgroundBehavior.STOP;
case "continue": return VideoBackgroundBehavior.CONTINUE_PLAYING;
case "pip": //Deliberate fall-through
default: return VideoBackgroundBehavior.PICTURE_IN_PICTURE;
}
}
public static EpisodeCleanupAlgorithm getEpisodeCleanupAlgorithm() {
if (!isEnableAutodownload()) {
return new APNullCleanupAlgorithm();
@ -973,10 +963,6 @@ public class UserPreferences {
return prefs.getBoolean(PREF_CAST_ENABLED, false);
}
public enum VideoBackgroundBehavior {
STOP, PICTURE_IN_PICTURE, CONTINUE_PLAYING
}
public enum BackButtonBehavior {
DEFAULT, OPEN_DRAWER, DOUBLE_TAP, SHOW_PROMPT, GO_TO_PAGE
}

View File

@ -247,28 +247,6 @@
<item>@string/skip_episode_label</item>
</string-array>
<string-array name="video_background_behavior_options">
<item>@string/stop_playback</item>
<item>@string/player_go_to_picture_in_picture</item>
<item>@string/continue_playback</item>
</string-array>
<string-array name="video_background_behavior_values">
<item>stop</item>
<item>pip</item>
<item>continue</item>
</string-array>
<string-array name="video_background_behavior_options_without_pip">
<item>@string/stop_playback</item>
<item>@string/continue_playback</item>
</string-array>
<string-array name="video_background_behavior_values_without_pip">
<item>stop</item>
<item>continue</item>
</string-array>
<string-array name="back_button_behavior_options">
<item>@string/back_button_default</item>
<item>@string/back_button_go_to_page</item>

View File

@ -304,7 +304,6 @@
<string name="playback_error_unknown">Unknown Error</string>
<string name="no_media_playing_label">No media playing</string>
<string name="position_default_label" translatable="false">00:00:00</string>
<string name="player_go_to_picture_in_picture">Picture-in-picture mode</string>
<string name="unknown_media_key">AntennaPod - Unknown media key: %1$d</string>
<string name="error_file_not_found">File not found</string>
<string name="no_media_label">Item does not contain a media file</string>
@ -513,10 +512,6 @@
<string name="media_player_switch_to_exoplayer">Switch to ExoPlayer</string>
<string name="media_player_switched_to_exoplayer">Switched to ExoPlayer.</string>
<string name="pref_skip_silence_title">Skip Silence in Audio</string>
<string name="pref_videoBehavior_title">Upon exiting video</string>
<string name="pref_videoBehavior_sum">Behavior when leaving video playback</string>
<string name="stop_playback">Stop playback</string>
<string name="continue_playback">Continue audio playback</string>
<string name="behavior">Behavior</string>
<string name="pref_back_button_behavior_title">Back Button Behavior</string>
<string name="pref_back_button_behavior_sum">Change behavior of the back button.</string>
@ -794,6 +789,7 @@
<string name="stereo_to_mono">Downmix: Stereo to mono</string>
<string name="sonic_only">Sonic only</string>
<string name="exoplayer_only">ExoPlayer only</string>
<string name="player_switch_to_audio_only">Switch to audio only</string>
<!-- proxy settings -->
<string name="proxy_type_label">Type</string>