Skip to content

Commit

Permalink
build(project): fix building umd with current music-metadata library
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Nov 10, 2024
1 parent dcef0b2 commit 8603490
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
29 changes: 6 additions & 23 deletions libs/web-media/src/lib/audio/AudioFormats/music-metadata-format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AudioFormat } from './audio-format';
import { MpegParser, parseBlob, OggParser, MP4Parser, FlacParser} from 'music-metadata-remastered';
import { parseBlob } from 'music-metadata';

export class MusicMetadataFormat extends AudioFormat {
protected override _decoder: 'web-audio' | 'octra' = 'web-audio';
Expand Down Expand Up @@ -34,42 +34,25 @@ export class MusicMetadataFormat extends AudioFormat {
}

override async readAudioInformation(buffer: ArrayBuffer) {
let parser: any | undefined;
const ext = this._filename.substring(this._filename.lastIndexOf("."));

switch (ext) {
case ".mp3":
parser = MpegParser;
break;
case ".ogg":
parser = OggParser;
break;
case ".m4a":
parser = MP4Parser;
break;
case ".flac":
parser = FlacParser;
break;
}

const parsed = await parseBlob(
new File([buffer], this._filename, { type: this._mimeType }),
parser
new File([buffer], this._filename, { type: this._mimeType })
);
const format = parsed.format;

if (
!format.sampleRate ||
!format.numberOfSamples ||
!(format.numberOfSamples || format.duration) ||
!format.numberOfChannels
) {
throw new Error(
"Can't read one of the following audio information: sampleRate, numberOfSamples, numberOfChannels."
);
} else {
const numberOfSamples =
format.numberOfSamples ?? Math.ceil(format.duration! * format.sampleRate);
this._sampleRate = format.sampleRate;
this._duration = {
samples: format.numberOfSamples,
samples: numberOfSamples,
seconds: format.duration!,
};
this._channels = format.numberOfChannels;
Expand Down
1 change: 1 addition & 0 deletions libs/web-media/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineConfig({
'@octra/utilities': 'OctraUtilities',
'@octra/media': 'OctraMedia',
},
inlineDynamicImports: true
},
// External packages that should not be bundled into your library.
external: ['@octra/utilities', '@octra/media'],
Expand Down
35 changes: 24 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"jest-environment-jsdom": "29.7.0",
"jest-preset-angular": "14.1.0",
"jsonc-eslint-parser": "^2.1.0",
"music-metadata-remastered": "file:music-metadata-remastered-0.0.1.tgz",
"music-metadata": "^10.5.1",
"ng-packagr": "18.2.1",
"ngx-deploy-npm": "8.2.0",
"nx": "20.0.11",
Expand Down

0 comments on commit 8603490

Please sign in to comment.