mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Add metadata-based duration retrieval
This commit is contained in:
@@ -97,6 +97,17 @@ export class FlacDemuxer extends Demuxer {
|
||||
return [this.track];
|
||||
}
|
||||
|
||||
async getDurationFromMetadata(): Promise<number | null> {
|
||||
await this.readMetadata();
|
||||
assert(this.audioInfo);
|
||||
|
||||
if (this.audioInfo.totalSamples === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.audioInfo.totalSamples / this.audioInfo.sampleRate;
|
||||
}
|
||||
|
||||
async getMimeType() {
|
||||
return 'audio/flac';
|
||||
}
|
||||
@@ -252,6 +263,10 @@ export class FlacDemuxer extends Demuxer {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.audioInfo) {
|
||||
throw new Error('Missing STREAMINFO metadata block! Corrupted FLAC file.');
|
||||
}
|
||||
})());
|
||||
}
|
||||
|
||||
@@ -578,6 +593,10 @@ class FlacAudioTrackBacking implements InputAudioTrackBacking {
|
||||
return null;
|
||||
}
|
||||
|
||||
getDurationFromMetadata() {
|
||||
return this.demuxer.getDurationFromMetadata();
|
||||
}
|
||||
|
||||
async getLiveRefreshInterval() {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user