Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class YoutubeAddon extends WebBrowserAddon implements PreferenceStore.Lis
private static final Pref<BooleanSupplier> YT_SKIP_ADD = AUTO ? Pref.b("YT_SKIP_ADD", true) : null;
private static final Pref<BooleanSupplier> YT_PLAYER_CONTROLS =
Pref.b("YT_PLAYER_CONTROLS", false);
private static final Pref<BooleanSupplier> YT_PAUSE_ON_LEAVE = Pref.b("YT_PAUSE_ON_LEAVE", !AUTO);
private boolean ignorePrefChange;

@IdRes
Expand Down Expand Up @@ -110,6 +111,13 @@ public void contributeSettings(Context ctx, PreferenceStore store, PreferenceSet
o.subtitle = R.string.youtube_player_controls_sub;
o.visibility = visibility;
});
set.addBooleanPref(o -> {
o.store = getPreferenceStore();
o.pref = YT_PAUSE_ON_LEAVE;
o.title = R.string.youtube_pause_on_leave;
o.subtitle = R.string.youtube_pause_on_leave_sub;
o.visibility = visibility;
});

if (AUTO) {
set.addBooleanPref(o -> {
Expand Down Expand Up @@ -174,6 +182,10 @@ void setScale(VideoScale scale) {
getPreferenceStore().applyStringPref(VIDEO_SCALE, scale.prefName());
}

boolean pauseOnLeave() {
return getPreferenceStore().getBooleanPref(YT_PAUSE_ON_LEAVE);
}

boolean autoHighestQuality() {
return getPreferenceStore().getBooleanPref(YT_AUTO_HIGHEST_QUALITY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.HashSet;
import java.util.Set;

import me.aap.fermata.BuildConfig;
import me.aap.fermata.addon.AddonManager;
import me.aap.fermata.addon.web.FermataChromeClient;
import me.aap.fermata.addon.web.FermataWebView;
Expand Down Expand Up @@ -133,7 +132,7 @@ protected void unregisterListeners(MainActivityDelegate a) {

@Override
public void onPause() {
if (!BuildConfig.AUTO) {
if ((getAddon() instanceof YoutubeAddon addon) && addon.pauseOnLeave()) {
MainActivityDelegate.getActivityDelegate(getContext()).onSuccess(a -> {
FermataServiceUiBinder b = a.getMediaServiceBinder();
if (YoutubeMediaEngine.isYoutubeItem(b.getCurrentItem()) && b.isPlaying()) {
Expand All @@ -150,7 +149,7 @@ public void onPause() {
@Override
public void onResume() {
super.onResume();
if (BuildConfig.AUTO || !playOnResume) return;
if (!playOnResume) return;
playOnResume = false;
MainActivityDelegate.getActivityDelegate(getContext()).onSuccess(a -> {
FermataServiceUiBinder b = a.getMediaServiceBinder();
Expand All @@ -177,7 +176,8 @@ public void onPlayableChanged(MediaLib.PlayableItem oldItem, MediaLib.PlayableIt
FermataChromeClient chrome = v.getWebChromeClient();
if (chrome == null) return;

if (!DEFAULT_URLS.contains(getUrl())) chrome.enterFullScreen();
// Only while on screen: off screen, full screen would hide the page and pause the video
if (isResumed() && !DEFAULT_URLS.contains(getUrl())) chrome.enterFullScreen();
} else if (YoutubeMediaEngine.isYoutubeItem(oldItem)) {
FermataWebView v = getWebView();
if (v == null) return;
Expand Down
2 changes: 2 additions & 0 deletions modules/web/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
<string name="sponsorblock_cat_music_offtopic">Non-music sections</string>
<string name="sponsorblock_cat_filler">Filler</string>
<string name="sponsorblock_cat_filler_sub">Aggressive category; disabled by default.</string>
<string name="youtube_pause_on_leave">Pause when leaving the screen</string>
<string name="youtube_pause_on_leave_sub">Pause when Fermata goes off screen and resume when it\'s back. Off: keep playing in the background</string>
</resources>
Loading