npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-audio-metadata

v2.1.1

Published

Extract audio metadata for React Native — New Architecture (TurboModules + JSI) with support for MP3, FLAC, WAV, AAC, M4A and more on iOS & Android.

Readme

react-native-audio-metadata

A React Native library to extract metadata and artwork from audio and video files on Android. Get information like title, artist, album, duration, year, genre, and artwork from your media files.

Features

  • Extract complete metadata from audio and video files
  • Get embedded artwork (album art) from audio files as base64
  • Get video thumbnails with configurable aspect ratio: 1:1 or 16:9
  • Black frame detection (returns null instead of black thumbnails)
  • Fast and efficient native implementation
  • Proper permission handling for Android 10, 11, and 13+

Installation

npm install react-native-audio-metadata

or

yarn add react-native-audio-metadata

Setup

Android Permissions

Add the following permissions to your android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

Request Permissions at Runtime

import { PermissionsAndroid, Platform } from 'react-native';

async function requestMediaPermissions() {
  if (Platform.OS !== 'android') return true;

  const androidVersion = Platform.Version;

  if (androidVersion >= 33) {
    const results = await PermissionsAndroid.requestMultiple([
      'android.permission.READ_MEDIA_AUDIO' as any,
      'android.permission.READ_MEDIA_VIDEO' as any,
    ]);

    return (
      results['android.permission.READ_MEDIA_AUDIO'] ===
        PermissionsAndroid.RESULTS.GRANTED &&
      results['android.permission.READ_MEDIA_VIDEO'] ===
        PermissionsAndroid.RESULTS.GRANTED
    );
  } else {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
    );
    return granted === PermissionsAndroid.RESULTS.GRANTED;
  }
}

Usage

import {
  getMetadata,
  getArtwork,
  type AudioMetadata,
} from 'react-native-audio-metadata';

async function extractInfo() {
  try {
    const filePath = '/storage/emulated/0/Music/song.mp3';

    // Get metadata (lightweight, text only)
    const metadata: AudioMetadata = await getMetadata(filePath);
    console.log('Title:', metadata.title);
    console.log('Artist:', metadata.artist);
    console.log('Duration:', metadata.duration);

    // Get artwork separately (heavier, returns base64 image)
    const artwork: string | null = await getArtwork(filePath);

    // For video files, you can specify the aspect ratio of the thumbnail
    const thumbnail16x9 = await getArtwork(
      '/storage/emulated/0/Movies/video.mp4',
      '16:9'
    );
    const thumbnail1x1 = await getArtwork(
      '/storage/emulated/0/Movies/video.mp4',
      '1:1'
    );
  } catch (error) {
    console.error('Error:', error);
  }
}

API

getMetadata(filePath: string): Promise<AudioMetadata>

Extracts text metadata from an audio or video file.

Returns

interface AudioMetadata {
  title?: string; // Title
  artist?: string; // Artist name
  album?: string; // Album name
  duration?: number; // Duration in milliseconds
  year?: string; // Release year
  genre?: string; // Genre
}

All fields are optional. If a field is not available, it will be undefined.


getArtwork(filePath: string, aspectRatio?: AspectRatio): Promise<string | null>

Extracts artwork from an audio or video file.

| Parameter | Type | Default | Description | | ------------- | ------------- | ------- | ----------------------------------------------------- | | filePath | string | — | Absolute path to the audio or video file | | aspectRatio | AspectRatio | '1:1' | Crop ratio for video thumbnails ('1:1' or '16:9') |

type AspectRatio = '1:1' | '16:9';
  • Audio files: Returns embedded album art (ID3 tags). aspectRatio is ignored.
  • Video files: Returns a cropped thumbnail frame from the video in the requested aspect ratio.
  • Returns null if no artwork is available or if the extracted frame is black.

The returned string is a base64 data URI (data:image/jpeg;base64,...).


Errors

Both functions may reject with the following error codes:

| Code | Description | | ------------------- | ---------------------------------- | | PERMISSION_DENIED | Missing required permissions | | INVALID_FILE | Invalid file or unsupported format | | ERROR | General error during extraction |

Example

Display Song Information with Artwork

import React, { useState } from 'react';
import { View, Text, Image, Button } from 'react-native';
import { getMetadata, getArtwork, type AudioMetadata } from 'react-native-audio-metadata';

function MusicPlayer() {
  const [metadata, setMetadata] = useState<AudioMetadata | null>(null);
  const [artwork, setArtwork] = useState<string | null>(null);

  const loadSong = async () => {
    const path = '/storage/emulated/0/Music/song.mp3';
    const [data, art] = await Promise.all([
      getMetadata(path),
      getArtwork(path),
    ]);
    setMetadata(data);
    setArtwork(art);
  };

  return (
    <View>
      <Button title="Load Song" onPress={loadSong} />

      {metadata && (
        <View>
          <Text>{metadata.title}</Text>
          <Text>{metadata.artist}</Text>
          <Text>{metadata.album}</Text>

          {artwork && (
            <Image
              source={{ uri: artwork }}
              style={{ width: 200, height: 200 }}
            />
          )}
        </View>
      )}
    </View>
  );
}

Video Thumbnail with Aspect Ratio

import { getArtwork } from 'react-native-audio-metadata';

// Square thumbnail (default) — ideal for grids or playlists
const square = await getArtwork('/storage/emulated/0/Movies/clip.mp4');

// Widescreen thumbnail — ideal for video players or cards
const wide = await getArtwork('/storage/emulated/0/Movies/clip.mp4', '16:9');

Format Duration

function formatDuration(ms: number): string {
  const minutes = Math.floor(ms / 1000 / 60);
  const seconds = Math.floor((ms / 1000) % 60);
  return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}

Process Multiple Files

async function processMultipleFiles(filePaths: string[]) {
  const batchSize = 10;
  const results = [];

  for (let i = 0; i < filePaths.length; i += batchSize) {
    const batch = filePaths.slice(i, i + batchSize);
    const batchResults = await Promise.all(
      batch.map(async (path) => ({
        metadata: await getMetadata(path),
        artwork: await getArtwork(path),
      }))
    );
    results.push(...batchResults);
  }

  return results;
}

Supported Formats

The library supports all formats supported by Android's MediaMetadataRetriever:

Audio: MP3, MP4/M4A, WAV, FLAC, OGG, AAC, 3GP, and more.

Video: MP4, MKV, MOV, 3GP, and more.

Platform Support

| Platform | Supported | | -------- | --------- | | Android | Yes | | iOS | Yes |

File not found

Make sure you are using the absolute path to the file:

  • /storage/emulated/0/Music/song.mp3
  • ~/Music/song.mp3

Permission denied

  1. Make sure permissions are declared in AndroidManifest.xml
  2. Request permissions at runtime (especially for Android 13+)
  3. Confirm the user granted the permissions

Artwork returns null for audio

The file may not have embedded artwork in its ID3 tags.

Artwork returns null for video

The extracted frame may be black (the library detects this and returns null). Try a file with visible content.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library