@missingcore/audio-metadata v1.3.0
@missingcore/audio-metadata
An audio file metadata reader built primarily for React Native (mobile only) supporting tags used in MissingCore/Music
.
!NOTE
Supports React Native's "New Architecture".Also works in a plain Node.js environment.
Supported Files
Extension | Format | Additional Information |
---|---|---|
.flac | - FLAC | |
.mp3 | - ID3v1- ID3v2 | - Unsynchronisation supported- Tag at end of file supported (ID3v2.4)- All other flags ignored |
.mp4 /.m4a | - MP-4 Part 14 (a.k.a. MP4) |
* Currently untested as I have no
.mp3
files that meets those conditions. Feel free to submit an issue to tell me if it works or doesn't work.
Installation
React Native
!IMPORTANT
Currently, this library only supportsReact Native 0.74.0
orExpo SDK 51
and newer due to the introduction of nativeatob()
&btoa()
support.In the future, we may support older versions with a peer dependency of
base-64
.
This library supports using either expo-file-system
or @dr.pogodin/react-native-fs
(a more actively maintained fork of react-native-fs
).
Note: Using
@dr.pogodin/react-native-fs
withexpo
requires a bare workflow.
Regardless of which file system library you use, they perform relatively the same.
With expo-file-system
npx expo install @missingcore/audio-metadata expo-file-system
With @dr.pogodin/react-native-fs
npm install @missingcore/audio-metadata @dr.pogodin/react-native-fs
Node.js
This library supports Node.js as it supplements the file system operations by using native Node.js modules.
Usage
import { getAudioMetadata } from '@missingcore/audio-metadata';
const uri = 'file:///storage/emulated/0/Music/Silence.mp3';
const wantedTags = ['album', 'albumArtist', 'artist', 'name', 'track', 'year'] as const;
// Of course with `await`, use this inside an async function or use `Promise.then()`.
const data = await getAudioMetadata(uri, wantedTags);
/*
Returns:
{
fileType: 'mp3',
format: 'ID3v2.3',
metadata: {
album: 'Void';
albumArtist: 'Nothing';
artist: 'Nothing';
name: 'Silence';
track: 1;
year: 2024;
}
}
*/
Supported Tags
The full list of supported tags found here.
type AudioMetadata = {
album: string;
albumArtist: string;
artist: string;
artwork: string; // A base64 image string.
name: string;
track: number;
year: number;
};
❗Note❗ that not all of the requested metadata may be present in the file read. In the returned metadata
value, all the fields we want are "optional" (ie: its value can be undefined
).