From 0cce72b24b25f408059f21042d10b0e39ede990b Mon Sep 17 00:00:00 2001 From: Jade Macho Date: Fri, 1 Mar 2024 21:20:24 +0100 Subject: [PATCH] Allow manually forcing HLS.js on --- ...atchAndroidHLSJS.js => PatchForceHLSJS.js} | 37 ++++++++++++++++++- mods_jade.json | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) rename mods/jade/{PatchAndroidHLSJS.js => PatchForceHLSJS.js} (51%) diff --git a/mods/jade/PatchAndroidHLSJS.js b/mods/jade/PatchForceHLSJS.js similarity index 51% rename from mods/jade/PatchAndroidHLSJS.js rename to mods/jade/PatchForceHLSJS.js index 3c05462..f5b3bf1 100644 --- a/mods/jade/PatchAndroidHLSJS.js +++ b/mods/jade/PatchForceHLSJS.js @@ -6,7 +6,7 @@ import Jadefin from "../../Jadefin.js"; import JadefinMod from "../../JadefinMod.js"; import JadefinModules from "../../JadefinModules.js"; -// https://github.com/jellyfin/jellyfin-android/issues/1031 +// Mainly spawned from https://github.com/jellyfin/jellyfin-android/issues/1031 export default JadefinIntegrity("PatchAndroidHLSJS", import.meta.url, () => new (class PatchAndroidHLSJS extends JadefinMod { constructor() { super(); @@ -14,6 +14,14 @@ export default JadefinIntegrity("PatchAndroidHLSJS", import.meta.url, () => new this.enableHlsJsPlayer = this.enableHlsJsPlayer.bind(this); } + get isEnabled() { + return this.storage.get("isEnabled", false); + } + + set isEnabled(value) { + this.storage.set("isEnabled", value); + } + async init(name, url) { await super.init(name, url); @@ -21,9 +29,36 @@ export default JadefinIntegrity("PatchAndroidHLSJS", import.meta.url, () => new this._enableHlsJsPlayer = htmlMediaHelper.rR.bind(htmlMediaHelper); Object.defineProperty(htmlMediaHelper, "rR", { get: () => this.enableHlsJsPlayer }); + + const ExtrasMenu = /** @type {import("../ExtrasMenu.js").default} */ (Jadefin.getMod("ExtrasMenu")); + + ExtrasMenu.items.push({ + name: "Enable HLS.js", + secondaryText: "Sometimes helps with playback in some browsers", + icon: "auto_fix_normal", + in: ExtrasMenu.IN_CUSTOM, + inCustom: (current, item) => { + if (!this.isEnabled) { + item.name = "Enable HLS.js"; + item.icon = "auto_fix_normal"; + } else { + item.name = "Disable HLS.js"; + item.icon = "auto_fix_off"; + } + + return true; + }, + cb: () => { + this.isEnabled = !this.isEnabled; + } + }); } enableHlsJsPlayer(runTimeTicks, mediaType) { + if (this.isEnabled) { + return true; + } + // https://github.com/jellyfin/jellyfin-web/commit/baf1b55a0cb83d4cb63a18968fc93493ce785498 if (JadefinModules.browser.android && mediaType === "Video") { mediaType = "Audio"; diff --git a/mods_jade.json b/mods_jade.json index 8ceb8e2..22460f0 100644 --- a/mods_jade.json +++ b/mods_jade.json @@ -8,5 +8,5 @@ "Transcript.js", "jade/Shortcuts.js", - "jade/PatchAndroidHLSJS.js" + "jade/PatchForceHLSJS.js" ] \ No newline at end of file