Commit 10521084 authored by Skye Yu's avatar Skye Yu

fix: audio file download interrupted

parent a1fb1c1f
...@@ -709,16 +709,15 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -709,16 +709,15 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
audio.loop = true; audio.loop = true;
audio.controls = false; audio.controls = false;
audio.autoplay = true; audio.autoplay = true;
audio.muted = true;
document.body.appendChild(audio); document.body.appendChild(audio);
} }
if (document.visibilityState === 'hidden') { if (document.visibilityState === 'hidden') {
console.log('Page is hidden'); console.log('Page is hidden');
audio.play(); audio.play();
// 可以选择暂停数据传输,或通过 Web Worker 继续后台任务
} else { } else {
audio.pause(); audio.pause();
console.log('Page is visible'); console.log('Page is visible');
// 重新开始或恢复数据传输
} }
} }
...@@ -730,12 +729,12 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -730,12 +729,12 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
flen += msg.body.length || msg.body.byteLength; flen += msg.body.length || msg.body.byteLength;
ondata(msg.body); ondata(msg.body);
if (flen >= length) { if (flen >= length) {
// document.removeEventListener('visibilitychange', visibilitychange); document.removeEventListener('visibilitychange', visibilitychange);
// return OK indicates all file blocks received // return OK indicates all file blocks received
return 'OK'; return 'OK';
} }
} else { } else {
// document.removeEventListener('visibilitychange', visibilitychange); document.removeEventListener('visibilitychange', visibilitychange);
ondata('fail'); ondata('fail');
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment