修改为下载完成之后才播放
This commit is contained in:
@@ -432,11 +432,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let hasDownloadCompleted = false;
|
||||||
|
|
||||||
const handleProgress = (progress) => {
|
const handleProgress = (progress) => {
|
||||||
if (!progress) return;
|
if (!progress) return;
|
||||||
const status = progress.status;
|
const status = progress.status;
|
||||||
|
|
||||||
if (status === 'downloading') {
|
if (status === 'downloading') {
|
||||||
|
hasDownloadCompleted = false;
|
||||||
showDownloadPhase();
|
showDownloadPhase();
|
||||||
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
|
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
|
||||||
updateTranscodeProgressBar(percent);
|
updateTranscodeProgressBar(percent);
|
||||||
@@ -446,6 +449,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
downloadProgressText.textContent = `${percent}%`;
|
downloadProgressText.textContent = `${percent}%`;
|
||||||
downloadProgressFill.style.width = `${percent}%`;
|
downloadProgressFill.style.width = `${percent}%`;
|
||||||
} else if (status === 'downloaded') {
|
} else if (status === 'downloaded') {
|
||||||
|
hasDownloadCompleted = true;
|
||||||
showDownloadPhase();
|
showDownloadPhase();
|
||||||
updateTranscodeProgressBar(100);
|
updateTranscodeProgressBar(100);
|
||||||
const downloaded = formatBytes(progress.downloadedBytes || progress.totalBytes || 0);
|
const downloaded = formatBytes(progress.downloadedBytes || progress.totalBytes || 0);
|
||||||
@@ -457,6 +461,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
showTranscodePhase();
|
showTranscodePhase();
|
||||||
}, 600);
|
}, 600);
|
||||||
} else if (status === 'transcoding') {
|
} else if (status === 'transcoding') {
|
||||||
|
hasDownloadCompleted = true;
|
||||||
showTranscodePhase();
|
showTranscodePhase();
|
||||||
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
|
const percent = Math.min(Math.max(Math.round(progress.percent || 0), 0), 100);
|
||||||
updateTranscodeProgressBar(percent);
|
updateTranscodeProgressBar(percent);
|
||||||
@@ -471,6 +476,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
statTime.textContent = progress.timemark ? `${progress.timemark}` : '';
|
statTime.textContent = progress.timemark ? `${progress.timemark}` : '';
|
||||||
}
|
}
|
||||||
} else if (status === 'finished') {
|
} else if (status === 'finished') {
|
||||||
|
hasDownloadCompleted = true;
|
||||||
showTranscodePhase();
|
showTranscodePhase();
|
||||||
updateTranscodeProgressBar(100);
|
updateTranscodeProgressBar(100);
|
||||||
transcodeProgressText.textContent = '100%';
|
transcodeProgressText.textContent = '100%';
|
||||||
@@ -498,6 +504,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const resetPhases = () => {
|
const resetPhases = () => {
|
||||||
|
hasDownloadCompleted = false;
|
||||||
if (downloadPhase) downloadPhase.classList.remove('hidden');
|
if (downloadPhase) downloadPhase.classList.remove('hidden');
|
||||||
if (downloadSizeText) downloadSizeText.textContent = '准备下载...';
|
if (downloadSizeText) downloadSizeText.textContent = '准备下载...';
|
||||||
if (downloadProgressText) downloadProgressText.textContent = '0%';
|
if (downloadProgressText) downloadProgressText.textContent = '0%';
|
||||||
@@ -1237,7 +1244,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const streamUrl = buildStreamUrl();
|
const streamUrl = buildStreamUrl();
|
||||||
videoPlayer.src = streamUrl;
|
videoPlayer.src = streamUrl;
|
||||||
videoPlayer.load();
|
videoPlayer.load();
|
||||||
videoPlayer.addEventListener('loadedmetadata', () => {
|
const onCanPlayAfterDownload = () => {
|
||||||
|
if (!hasDownloadCompleted) return;
|
||||||
|
videoPlayer.removeEventListener('canplay', onCanPlayAfterDownload);
|
||||||
syncVideoDurationFromPlayer();
|
syncVideoDurationFromPlayer();
|
||||||
transcodingOverlay.classList.add('hidden');
|
transcodingOverlay.classList.add('hidden');
|
||||||
videoPlayer.classList.remove('hidden');
|
videoPlayer.classList.remove('hidden');
|
||||||
@@ -1250,10 +1259,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
updateVolumeControls();
|
updateVolumeControls();
|
||||||
updateFullscreenControls();
|
updateFullscreenControls();
|
||||||
schedulePlaybackChromeHide();
|
schedulePlaybackChromeHide();
|
||||||
|
videoPlayer.play().catch(() => {});
|
||||||
loadSubtitleTracks(seekOffset).catch((error) => {
|
loadSubtitleTracks(seekOffset).catch((error) => {
|
||||||
console.error('Subtitle load failed:', error);
|
console.error('Subtitle load failed:', error);
|
||||||
});
|
});
|
||||||
}, { once: true });
|
};
|
||||||
|
videoPlayer.addEventListener('canplay', onCanPlayAfterDownload);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
transcodingOverlay.innerHTML = `<p style="color: #ef4444;">Transcode Failed: ${err.message}</p>`;
|
transcodingOverlay.innerHTML = `<p style="color: #ef4444;">Transcode Failed: ${err.message}</p>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user