Skip to content

Commit

Permalink
fix(YouTube - Video playback): Correctly set default quality when cha…
Browse files Browse the repository at this point in the history
…nging from a low quality video
  • Loading branch information
inotia00 authored and anddea committed Dec 11, 2024
1 parent b934073 commit 8cbe976
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.annotation.NonNull;

import app.revanced.extension.shared.settings.IntegerSetting;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.Utils;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
Expand Down Expand Up @@ -58,11 +59,11 @@ private static void setVideoQuality(final long delayMillis) {
if (defaultQuality == DEFAULT_YOUTUBE_VIDEO_QUALITY)
return;

Utils.runOnMainThreadDelayed(() ->
VideoInformation.overrideVideoQuality(
VideoInformation.getAvailableVideoQuality(defaultQuality)
),
delayMillis
Utils.runOnMainThreadDelayed(() -> {
final int qualityToUseFinal = VideoInformation.getAvailableVideoQuality(defaultQuality);
Logger.printDebug(() -> "Changing video quality to: " + qualityToUseFinal);
VideoInformation.overrideVideoQuality(qualityToUseFinal);
}, delayMillis
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public final class VideoInformation {
@Nullable
private static List<Integer> videoQualities;

private static boolean qualityNeedsUpdating;

/**
* Injection point.
*/
Expand Down Expand Up @@ -415,16 +417,18 @@ public static void setVideoQuality(String newlyLoadedQuality) {
* @return available video quality.
*/
public static int getAvailableVideoQuality(int preferredQuality) {
if (videoQualities != null) {
int qualityToUse = videoQualities.get(0); // first element is automatic mode
for (Integer quality : videoQualities) {
if (quality <= preferredQuality && qualityToUse < quality) {
qualityToUse = quality;
}
if (!qualityNeedsUpdating || videoQualities == null) {
return preferredQuality;
}
qualityNeedsUpdating = false;

int qualityToUse = videoQualities.get(0); // first element is automatic mode
for (Integer quality : videoQualities) {
if (quality <= preferredQuality && qualityToUse < quality) {
qualityToUse = quality;
}
preferredQuality = qualityToUse;
}
return preferredQuality;
return qualityToUse;
}

/**
Expand All @@ -444,6 +448,7 @@ public static void setVideoQualityList(Object[] qualities) {
}
}
}
qualityNeedsUpdating = true;
Logger.printDebug(() -> "videoQualities: " + videoQualities);
}
} catch (Exception ex) {
Expand Down

0 comments on commit 8cbe976

Please sign in to comment.