fix media playback errors in firefox

This commit is contained in:
Samidy 2026-03-11 09:13:28 +03:00
parent 07003f92f0
commit 17964a8bc9
2 changed files with 53 additions and 14 deletions

View file

@ -2222,7 +2222,7 @@
<input <input
type="search" type="search"
id="search-input" id="search-input"
placeholder="Search for tracks, artists, albums..." placeholder="Search fffor tracks, artists, f"
autocomplete="off" autocomplete="off"
autocorrect="off" autocorrect="off"
autocapitalize="off" autocapitalize="off"

View file

@ -69,6 +69,9 @@ export class Player {
buffer: { buffer: {
fastSwitchEnabled: true, fastSwitchEnabled: true,
}, },
protection: {
ignoreProtection: true,
},
}, },
}); });
this.dashInitialized = false; this.dashInitialized = false;
@ -106,6 +109,19 @@ export class Player {
this._setupVideoSync(); this._setupVideoSync();
} }
_resetDashPlayer() {
if (this.dashInitialized && this.dashPlayer) {
try { this.dashPlayer.attachView(null); } catch (e) {}
try { this.dashPlayer.destroy(); } catch (e) {}
this.dashPlayer = MediaPlayer().create();
this.dashPlayer.updateSettings({
streaming: {
buffer: { fastSwitchEnabled: true },
},
});
this.dashInitialized = false;
}
}
_setupVideoSync() { _setupVideoSync() {
if (!this.video || !this.audio) return; if (!this.video || !this.audio) return;
@ -620,10 +636,7 @@ export class Player {
this.hls.destroy(); this.hls.destroy();
this.hls = null; this.hls = null;
} }
if (this.dashInitialized) { this._resetDashPlayer();
this.dashPlayer.reset();
this.dashInitialized = false;
}
if (inactiveElement) { if (inactiveElement) {
inactiveElement.pause(); inactiveElement.pause();
@ -799,8 +812,13 @@ export class Player {
if (streamUrl.includes('.m3u8') || streamUrl.includes('application/vnd.apple.mpegurl')) { if (streamUrl.includes('.m3u8') || streamUrl.includes('application/vnd.apple.mpegurl')) {
this.setupHlsVideo(activeElement, streamUrl, null); this.setupHlsVideo(activeElement, streamUrl, null);
} else if (streamUrl.startsWith('blob:') || streamUrl.includes('.mpd')) { } else if (streamUrl.startsWith('blob:') || streamUrl.includes('.mpd')) {
this.dashPlayer.initialize(activeElement, streamUrl, false); try {
this.dashInitialized = true; this.dashPlayer.initialize(activeElement, streamUrl, false);
this.dashInitialized = true;
} catch (e) {
console.error('DashPlayer initialize failed for video:', e);
throw new Error('DASH initialization failed');
}
} else { } else {
activeElement.src = streamUrl; activeElement.src = streamUrl;
} }
@ -851,6 +869,9 @@ export class Player {
streamUrl = trackData.originalTrackUrl; streamUrl = trackData.originalTrackUrl;
} else if (trackData.info?.manifest) { } else if (trackData.info?.manifest) {
streamUrl = this.api.extractStreamUrlFromManifest(trackData.info.manifest); streamUrl = this.api.extractStreamUrlFromManifest(trackData.info.manifest);
if (!streamUrl) {
streamUrl = await this.api.getStreamUrl(track.id, this.quality);
}
} else { } else {
streamUrl = await this.api.getStreamUrl(track.id, this.quality); streamUrl = await this.api.getStreamUrl(track.id, this.quality);
} }
@ -859,20 +880,36 @@ export class Player {
if (this.playbackSequence !== currentSequence) return; if (this.playbackSequence !== currentSequence) return;
// Handle playback // Handle playback
if (streamUrl && streamUrl.startsWith('blob:') && !track.isLocal) { if (streamUrl && (streamUrl.startsWith('blob:') || streamUrl.includes('.mpd')) && !track.isLocal) {
// It's likely a DASH manifest blob URL // It's likely a DASH manifest blob URL
this.dashPlayer.initialize(activeElement, streamUrl, false); try {
this.dashInitialized = true; this.dashPlayer.initialize(activeElement, streamUrl, false);
this.applyAudioEffects(); this.dashInitialized = true;
this.applyAudioEffects();
if (startTime > 0) { if (startTime > 0) {
this.dashPlayer.seek(startTime); this.dashPlayer.seek(startTime);
}
const canPlay = await this.waitForCanPlayOrTimeout(activeElement);
if (!canPlay || this.playbackSequence !== currentSequence) return;
await this.safePlay(activeElement);
} catch (e) {
console.error('DashPlayer initialize failed for audio:', e);
throw new Error('DASH initialization failed');
} }
} else if (streamUrl && (streamUrl.includes('.m3u8') || streamUrl.includes('application/vnd.apple.mpegurl'))) {
this.setupHlsVideo(activeElement, streamUrl, null);
this.applyAudioEffects();
const canPlay = await this.waitForCanPlayOrTimeout(activeElement); const canPlay = await this.waitForCanPlayOrTimeout(activeElement);
if (!canPlay || this.playbackSequence !== currentSequence) return; if (!canPlay || this.playbackSequence !== currentSequence) return;
if (startTime > 0) {
activeElement.currentTime = startTime;
}
await this.safePlay(activeElement); await this.safePlay(activeElement);
} else { } else if (streamUrl) {
activeElement.src = streamUrl; activeElement.src = streamUrl;
this.applyAudioEffects(); this.applyAudioEffects();
@ -885,6 +922,8 @@ export class Player {
} }
const played = await this.safePlay(activeElement); const played = await this.safePlay(activeElement);
if (!played) return; if (!played) return;
} else {
throw new Error('Could not resolve stream URL');
} }
} }