Fixed some seek issues

This commit is contained in:
killer069 2022-01-19 09:29:30 +05:30
parent c4d56b6c1f
commit 062a0e7851
2 changed files with 4 additions and 4 deletions

View File

@ -148,7 +148,7 @@ export class SeekStream {
this.timer.reuse(); this.timer.reuse();
return this.seek(); return this.seek();
} }
const bytes = this.stream.seek(); const bytes = this.stream.seek(this.content_length);
if (bytes instanceof Error) { if (bytes instanceof Error) {
this.stream.emit('error', bytes); this.stream.emit('error', bytes);
this.bytes_count = 0; this.bytes_count = 0;

View File

@ -75,7 +75,7 @@ export class WebmSeeker extends Duplex {
_read() {} _read() {}
seek(): Error | number { seek(content_length: number): Error | number {
let clusterlength = 0, let clusterlength = 0,
position = 0; position = 0;
let time_left = (this.sec - this.time) * 1000 || 0; let time_left = (this.sec - this.time) * 1000 || 0;
@ -86,8 +86,7 @@ export class WebmSeeker extends Duplex {
const data = this.header.segment.cues[i]; const data = this.header.segment.cues[i];
if (Math.floor((data.time as number) / 1000) === this.time) { if (Math.floor((data.time as number) / 1000) === this.time) {
position = data.position as number; position = data.position as number;
if (this.header.segment.cues.length > 1) clusterlength = (this.header.segment.cues[i + 1]?.position || content_length) - position - 1;
clusterlength = this.header.segment.cues[i + 1].position! - position - 1;
break; break;
} else continue; } else continue;
} }
@ -145,6 +144,7 @@ export class WebmSeeker extends Duplex {
// stop parsing the header once we have found the correct cue // stop parsing the header once we have found the correct cue
if ( if (
ebmlID.name === 'cueClusterPosition' && ebmlID.name === 'cueClusterPosition' &&
this.header.segment.cues!.length > 2 &&
this.time === (this.header.segment.cues!.at(-2)!.time as number) / 1000 this.time === (this.header.segment.cues!.at(-2)!.time as number) / 1000
) )
this.emit('headComplete'); this.emit('headComplete');