mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add try catch to video.foreach and video.pause
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
export class ChunksService {
|
||||
|
||||
chunkSize: number
|
||||
private file: File
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
get totalChunks () {
|
||||
return Math.ceil(this.file.size / this.chunkSize);
|
||||
}
|
||||
|
||||
// Function to read a chunk of the file
|
||||
readChunk(start: number, end: number): Promise<ArrayBuffer> {
|
||||
const file = this.file
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
if (reader.result instanceof ArrayBuffer) {
|
||||
resolve(reader.result);
|
||||
} else {
|
||||
reject(new Error("Failed to read chunk"));
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsArrayBuffer(file.slice(start, end));
|
||||
});
|
||||
}
|
||||
|
||||
setFile(file) {
|
||||
this.file = file
|
||||
}
|
||||
|
||||
async getChunks(i: number,chunkSize: number) {
|
||||
i--
|
||||
if(i < this.totalChunks) {
|
||||
const start = i * chunkSize;
|
||||
const end = Math.min(start + chunkSize, this.file.size);
|
||||
const chunk = await this.readChunk(start, end);
|
||||
|
||||
return chunk
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user