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 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-tag-reader

v0.3.1

Published

An Expo Modules that reads metadata from audio files

Downloads

92

Readme

expo-tag-reader

wakatime

expo-tag-reader is an Android only Expo module that allows you to read audio file tags and metadata from your React Native Expo application. It provides simple functions to read tags from individual audio files or to scan directories for audio files and retrieve their metadata.

This was created for use in my project "Flora".

Installation

bunx expo install expo-tag-reader

Usage

First, import the functions you need from the package:

import { readTags, readAudioFiles, ... or other functions } from "expo-tag-reader";

Reading tags from a single audio file

const fileUri = "file:///path/to/your/audio/file.mp3";
try {
    const tags = readTags(fileUri);
    console.log(tags);
} catch (error) {
    console.error("Error reading tags:", error);
}

Scanning directories for audio files

try {
    // REQUEST READ PERMISSIONS FIRST
    const pageSize = 5;
    let pageNumber = 1;
    let currentPage;

    do {
        currentPage = await readAudioFiles(pageSize, pageNumber);
        pageNumber++;
        console.log(currentPage); // current page files
    } while (currentPage.length === pageSize);
} catch (error) {
    console.error("Error reading audio files:", error);
}

API Reference

readTags()

Reads the tags from the audio file at the given URI.

  • fileUri: The URI of the audio file to read tags from.
  • disableTags (optional): Add any of the AudioFile properties to ignore.
  • cacheImages (optional): Whether to cache album art images. Defaults to true. If caching is enabled, the artwork property of AudioTags will be a URI, otherwise it will be Base64.
  • Returns: An object of type AudioTags.

readAudioFiles()

Reads all audio files from the Music and Downloads directory.

  • pageSize (optional): The number of audio files to return per page. Defaults to 10.
  • pageNumber: The page number to return. Defaults to 1.
  • cacheImages (optional): Whether to cache album art images. Defaults to true.
  • disableTags (optional): Add any of the AudioFile properties to ignore.
  • Returns: A Promise that resolves with an array of objects of type AudioFile.

setCustomDirectories()

Sets the custom directories to read audio files from.

  • dirPaths: An array of paths to directories that contain audio files.
  • Returns: A Promise that resolves when the operation is complete.

readNewAudioFiles()

Finds and returns new audio files by comparing IDs.

  • songIds: The IDs of the songs to read new files from.
  • pageSize (optional): The number of audio files to return per page. Defaults to 10.
  • pageNumber: The page number to return. Defaults to 1.
  • cacheImages (optional): Whether to cache album art images. Defaults to true.
  • disableTags (optional): Add any of the AudioFile properties to ignore.
  • Returns: A Promise that resolves with an array of objects of type AudioFile.

getRemovedAudioFiles()

Finds and returns the removed audio files by comparing IDs.

  • songIds: The IDs of the songs to find removed files from.
  • Returns: A Promise that resolves with an array of strings of removed file IDs.

Types

AudioTags

type AudioTags = {
    title: string;
    artist: string;
    album: string;
    year: string;
    genre: string;
    track: string;
    comment: string;
    albumArt: string; // URI or Base64 (default: URI)
    sampleRate: string;
    bitrate: string;
    channels: string;
    duration: string; // in ms
};

AudioFile

type AudioFile = {
    extension: string;
    uri: string;
    fileName: string;
    tags: AudioTags;
    creationDate: string; // in "dd-MM-yyyy"
    internalId: string; // unique identifier for the audio file
};

Supported File Formats

The module supports reading tags from the following audio file formats:

  • MP3
  • WAV
  • OGG
  • FLAC
  • M4A
  • OPUS
  • AIF
  • DSF
  • WMA

Platform Support

This module is currently implemented for Android only.

Important Notes

  • Remember to request read permissions before calling any of the audio file reading functions.
  • Caching images is faster than using base64 images on subsequent reads.
  • The internalId property in the AudioFile type is essential for tracking new and removed files.