@@ -164,6 +164,51 @@ export default {
164164 "https://unpkg.com/vue@2.6.10/dist/vue.js"
165165 ) ;
166166
167+ async function downloadBlobUrlWithProgressMultiChunk (
168+ url ,
169+ progressCallback ,
170+ chunkSize = 65536
171+ ) {
172+ const response = await fetch ( url ) ;
173+ if ( ! response . ok ) {
174+ throw new Error ( `Error: ${ response . status } - ${ response . statusText } ` ) ;
175+ }
176+ const contentLength = response . headers . get ( "content-length" ) ;
177+ const total = parseInt ( contentLength , 10 ) ;
178+ let loaded = 0 ;
179+ const startTime = Date . now ( ) ;
180+
181+ const chunks = [ ] ;
182+ const numChunks = Math . ceil ( total / chunkSize ) ;
183+ const promises = [ ] ;
184+
185+ for ( let i = 0 ; i < numChunks ; i ++ ) {
186+ const start = i * chunkSize ;
187+ const end = Math . min ( start + chunkSize - 1 , total - 1 ) ;
188+ promises . push (
189+ fetch ( url + `&range=${ start } -${ end } ` ) . then ( ( res ) => res . blob ( ) )
190+ ) ;
191+ }
192+
193+ await Promise . all ( promises )
194+ . then ( ( downloadedChunks ) => {
195+ chunks . push ( ...downloadedChunks ) ;
196+ loaded = total ;
197+ progressCallback ?. ( {
198+ loaded,
199+ total,
200+ speed : loaded / ( ( Date . now ( ) - startTime + 1 ) / 1000 ) ,
201+ } ) ;
202+ } )
203+ . catch ( ( error ) => {
204+ console . error ( "Download error:" , error ) ;
205+ } ) ;
206+
207+ return new Blob ( chunks , {
208+ type : response . headers . get ( "content-type" ) ,
209+ } ) ;
210+ }
211+
167212 const xhrDownloadUint8Array = async (
168213 { url, contentLength } ,
169214 progressCb
@@ -323,6 +368,25 @@ export default {
323368 this . audio . total = ( e . total / 1024 / 1024 ) . toFixed ( 2 ) ;
324369 this . audio . speed = ( e . speed / 1024 ) . toFixed ( 2 ) ;
325370 } ) ;
371+
372+ // const vPromise = downloadBlobUrlWithProgressMultiChunk(
373+ // videoObj.url,
374+ // ({ loaded, total, speed }) => {
375+ // this.video.progress = (loaded / total) * 100;
376+ // this.video.loaded = (loaded / 1024 / 1024).toFixed(2);
377+ // this.video.total = (total / 1024 / 1024).toFixed(2);
378+ // this.video.speed = (speed / 1024).toFixed(2);
379+ // }
380+ // );
381+ // const aPromise = downloadBlobUrlWithProgressMultiChunk(
382+ // audioObj.url,
383+ // ({ loaded, total, speed }) => {
384+ // this.audio.progress = (loaded / total) * 100;
385+ // this.audio.loaded = (loaded / 1024 / 1024).toFixed(2);
386+ // this.audio.total = (total / 1024 / 1024).toFixed(2);
387+ // this.audio.speed = (speed / 1024).toFixed(2);
388+ // }
389+ // );
326390 const [ varr , aarr ] = await Promise . all ( [ vPromise , aPromise ] ) ;
327391 this . merging = true ;
328392 win . onunload = ( ) => {
0 commit comments