An audio file metadata reader built for React Native.
npm install @missingcore/audio-metadataMissingCore/Music.
.flac | - FLAC | |
.mp3 | - ID3v1.mp4/.m4a | - MP-4 Part 14 (a.k.a. MP4) | |
.mp3 files that meets those conditions. Feel free to submit an issue to tell me if it works or doesn't work.
React Native 0.74.0 or Expo SDK 51 and newer due to the introduction of native atob() & btoa() support.
base-64.
expo-file-system or @dr.pogodin/react-native-fs (a more actively maintained fork of react-native-fs).
@dr.pogodin/react-native-fs with expo requires a bare workflow.
expo-file-system
sh
npx expo install @missingcore/audio-metadata expo-file-system
`
#### With @dr.pogodin/react-native-fs
`sh
npm install @missingcore/audio-metadata @dr.pogodin/react-native-fs
`
$3
This library supports Node.js as it supplements the file system operations by using native Node.js modules.
Usage
`tsx
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;
}
}
*/
`
$3
> The full list of supported tags found here.
`tsx
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`).