mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +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;
|
||||
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
|
||||
enableWorker: true,
|
||||
stashInitialSize: 64 * 1024, // Turbo Start: 64KB initial buffer
|
||||
stashInitialSize: 256 * 1024, // Optimized Turbo Start
|
||||
maxStashSize: 20 * 1024 * 1024 // 20MB buffer capacity
|
||||
});
|
||||
player.attachMediaElement(video);
|
||||
player.load();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
+15
-2
@@ -296,7 +296,7 @@
|
||||
url: url
|
||||
}, {
|
||||
enableWorker: true,
|
||||
stashInitialSize: 64 * 1024, // Turbo Start: 64KB initial buffer
|
||||
stashInitialSize: 256 * 1024, // Optimized Turbo Start: 256KB initial buffer
|
||||
enableStashBuffer: true,
|
||||
liveBufferLatencyChasing: true,
|
||||
liveBufferLatencyChasingOnPaused: true,
|
||||
@@ -310,7 +310,20 @@
|
||||
player.load();
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user