2024-03-01 21:01:22 +01:00
|
|
|
//@ts-check
|
|
|
|
|
2024-05-14 18:14:49 +02:00
|
|
|
import JadefinIntegrity from '../JadefinIntegrity.js';
|
2024-03-01 21:01:22 +01:00
|
|
|
|
2024-05-14 18:14:49 +02:00
|
|
|
import Jadefin from "../Jadefin.js";
|
|
|
|
import JadefinMod from "../JadefinMod.js";
|
|
|
|
import JadefinModules from "../JadefinModules.js";
|
|
|
|
import JadefinUtils from "../JadefinUtils.js";
|
2024-03-01 21:01:22 +01:00
|
|
|
|
2024-03-01 21:20:24 +01:00
|
|
|
// Mainly spawned from https://github.com/jellyfin/jellyfin-android/issues/1031
|
2024-03-01 21:01:22 +01:00
|
|
|
export default JadefinIntegrity("PatchAndroidHLSJS", import.meta.url, () => new (class PatchAndroidHLSJS extends JadefinMod {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.enableHlsJsPlayer = this.enableHlsJsPlayer.bind(this);
|
|
|
|
}
|
|
|
|
|
2024-03-01 21:20:24 +01:00
|
|
|
get isEnabled() {
|
2024-10-14 22:13:54 +02:00
|
|
|
return this.storage.get("isEnabled2", true);
|
2024-03-01 21:20:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set isEnabled(value) {
|
2024-10-14 22:13:54 +02:00
|
|
|
this.storage.set("isEnabled2", value);
|
2024-03-01 21:20:24 +01:00
|
|
|
}
|
|
|
|
|
2024-03-01 21:01:22 +01:00
|
|
|
async init(name, url) {
|
|
|
|
await super.init(name, url);
|
|
|
|
|
2024-05-14 18:14:49 +02:00
|
|
|
let enableHlsJsPlayerKey = [];
|
|
|
|
const htmlMediaHelper = this.htmlMediaPlayer = Jadefin.findWebpackRawLoad(
|
|
|
|
e => JadefinUtils.findDeep(
|
|
|
|
e,
|
|
|
|
1,
|
|
|
|
(i, o) => o.toString().indexOf(`.canPlayType("application/vnd.apple.mpegURL").replace(/no/,"")`) != -1,
|
|
|
|
(i, v, k) => enableHlsJsPlayerKey.push(k)
|
|
|
|
) && 1
|
|
|
|
)[0];
|
|
|
|
this._enableHlsJsPlayer = htmlMediaHelper[enableHlsJsPlayerKey[0]].bind(htmlMediaHelper);
|
2024-03-01 21:01:22 +01:00
|
|
|
|
2024-05-14 18:14:49 +02:00
|
|
|
Object.defineProperty(htmlMediaHelper, enableHlsJsPlayerKey[0], { get: () => this.enableHlsJsPlayer });
|
2024-03-01 21:20:24 +01:00
|
|
|
|
2024-05-14 18:14:49 +02:00
|
|
|
const ExtrasMenu = /** @type {import("./ExtrasMenu.js").default} */ (Jadefin.getMod("ExtrasMenu"));
|
2024-03-01 21:20:24 +01:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2024-05-13 20:48:11 +02:00
|
|
|
return (current & (ExtrasMenu.IN_LIBRARY | ExtrasMenu.IN_MOVIE)) == current;
|
2024-03-01 21:20:24 +01:00
|
|
|
},
|
|
|
|
cb: () => {
|
|
|
|
this.isEnabled = !this.isEnabled;
|
|
|
|
}
|
|
|
|
});
|
2024-03-01 21:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enableHlsJsPlayer(runTimeTicks, mediaType) {
|
2024-03-01 21:20:24 +01:00
|
|
|
if (this.isEnabled) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-01 21:01:22 +01:00
|
|
|
// https://github.com/jellyfin/jellyfin-web/commit/baf1b55a0cb83d4cb63a18968fc93493ce785498
|
|
|
|
if (JadefinModules.browser.android && mediaType === "Video") {
|
|
|
|
mediaType = "Audio";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._enableHlsJsPlayer?.(runTimeTicks, mediaType);
|
|
|
|
}
|
|
|
|
})());
|