mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-23 06:58:05 +02:00
perf(player): add MpegTS auto-recovery and optimize initial buffer to prevent Stream Error
This commit is contained in:
1 parent
b8922a2f08
commit
118887ab6f
2 files changed
+24
-4
No files matched your search
+9
-2
@@ -292,13 +292,20 @@
|
|||||||
if (!mpegts.isSupported()) return false;
|
if (!mpegts.isSupported()) return false;
|
||||||
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
|
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
stashInitialSize: 64 * 1024, // Turbo Start: 64KB initial buffer
|
stashInitialSize: 256 * 1024, // Optimized Turbo Start
|
||||||
maxStashSize: 20 * 1024 * 1024 // 20MB buffer capacity
|
maxStashSize: 20 * 1024 * 1024 // 20MB buffer capacity
|
||||||
});
|
});
|
||||||
player.attachMediaElement(video);
|
player.attachMediaElement(video);
|
||||||
player.load();
|
player.load();
|
||||||
player.play().catch(() => playOverlay.style.display = 'flex');
|
player.play().catch(() => playOverlay.style.display = 'flex');
|
||||||
player.on(mpegts.Events.ERROR, () => showError('Stream error'));
|
|
||||||
|
player.on(mpegts.Events.ERROR, (type, detail) => {
|
||||||
|
log('MpegTS Error: ' + type + ' - ' + detail);
|
||||||
|
setTimeout(() => {
|
||||||
|
player.destroy();
|
||||||
|
playWithMpegTS(url, isLive);
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -296,7 +296,7 @@
|
|||||||
url: url
|
url: url
|
||||||
}, {
|
}, {
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
stashInitialSize: 64 * 1024, // Turbo Start: 64KB initial buffer
|
stashInitialSize: 256 * 1024, // Optimized Turbo Start: 256KB initial buffer
|
||||||
enableStashBuffer: true,
|
enableStashBuffer: true,
|
||||||
liveBufferLatencyChasing: true,
|
liveBufferLatencyChasing: true,
|
||||||
liveBufferLatencyChasingOnPaused: true,
|
liveBufferLatencyChasingOnPaused: true,
|
||||||
@@ -310,7 +310,20 @@
|
|||||||
player.load();
|
player.load();
|
||||||
player.play().catch(() => playOverlay.style.display = 'flex');
|
player.play().catch(() => playOverlay.style.display = 'flex');
|
||||||
|
|
||||||
player.on(mpegts.Events.ERROR, () => showError('MpegTS Error'));
|
player.on(mpegts.Events.ERROR, (type, detail, info) => {
|
||||||
|
log('MpegTS Error: ' + type + ' - ' + detail);
|
||||||
|
// Auto-recover after 2 seconds
|
||||||
|
setTimeout(() => {
|
||||||
|
try {
|
||||||
|
player.unload();
|
||||||
|
player.detachMediaElement();
|
||||||
|
player.destroy();
|
||||||
|
playWithMpegTS(url, isLive);
|
||||||
|
} catch (e) {
|
||||||
|
showError('MpegTS Recovery Failed');
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user