修复不显示清空缓存按钮的BUG
This commit is contained in:
@@ -463,6 +463,34 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
seekToTime(targetTime);
|
||||
};
|
||||
|
||||
const seekToTime = (targetTime) => {
|
||||
if (!isStreamActive || videoDuration <= 0) return;
|
||||
const clampedTime = Math.max(0, Math.min(targetTime, videoDuration));
|
||||
console.log(`[Seek] Seeking to ${clampedTime.toFixed(2)}s / ${videoDuration.toFixed(2)}s`);
|
||||
|
||||
if (hlsInstance) {
|
||||
// For HLS: seek within the current buffer if possible
|
||||
const relativeTime = clampedTime - seekOffset;
|
||||
if (relativeTime >= 0 && relativeTime <= (videoPlayer.duration || 0)) {
|
||||
videoPlayer.currentTime = relativeTime;
|
||||
} else {
|
||||
// Need server-side restart from new position
|
||||
seekOffset = clampedTime;
|
||||
const streamUrl = buildHlsPlaylistUrl();
|
||||
hlsInstance.destroy();
|
||||
hlsInstance = new Hls({ maxBufferLength: 30, maxMaxBufferLength: 60 });
|
||||
hlsInstance.loadSource(streamUrl);
|
||||
hlsInstance.attachMedia(videoPlayer);
|
||||
hlsInstance.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
videoPlayer.play().catch(() => {});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
videoPlayer.currentTime = clampedTime;
|
||||
}
|
||||
updateSeekBarPosition(clampedTime);
|
||||
};
|
||||
|
||||
if (seekBar) {
|
||||
seekBar.addEventListener('mousedown', handleSeekStart);
|
||||
document.addEventListener('mousemove', handleSeekMove);
|
||||
@@ -898,10 +926,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
hlsInstance.loadSource(streamUrl);
|
||||
hlsInstance.attachMedia(videoPlayer);
|
||||
hlsInstance.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
console.log('[HLS] MANIFEST_PARSED - starting playback');
|
||||
transcodingOverlay.classList.add('hidden');
|
||||
videoPlayer.classList.remove('hidden');
|
||||
isStreamActive = true;
|
||||
videoPlayer.play().catch(() => { });
|
||||
videoPlayer.play().catch((e) => {
|
||||
console.warn('[HLS] Autoplay blocked:', e.message);
|
||||
});
|
||||
showSeekBar();
|
||||
showCustomControls();
|
||||
updatePlayControls();
|
||||
@@ -910,15 +941,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
schedulePlaybackChromeHide();
|
||||
});
|
||||
hlsInstance.on(Hls.Events.ERROR, function (event, data) {
|
||||
console.error('[HLS] Error:', data.type, data.details, data.fatal ? '(FATAL)' : '', data);
|
||||
if (data.fatal) {
|
||||
switch (data.type) {
|
||||
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||
console.warn('[HLS] Fatal network error, attempting recovery...');
|
||||
hlsInstance.startLoad();
|
||||
break;
|
||||
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||
console.warn('[HLS] Fatal media error, attempting recovery...');
|
||||
hlsInstance.recoverMediaError();
|
||||
break;
|
||||
default:
|
||||
console.error('[HLS] Fatal error, destroying instance');
|
||||
hlsInstance.destroy();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user