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

@kingfang007/react-native-get-music-files

v2.4.0

Published

React Native package to get music files from local and sd for iOS and Android

Downloads

9

Readme

react-native-get-music-files

React Native package to get music files from local and sd for iOS and Android

What does this package?

This package allow you to get music files from Android & iOS with following properties:

  • Title
  • Author
  • Album
  • Duration
  • FilePath
  • Cover
  • Duration
  • Genre

Getting started

$ yarn add react-native-get-music-files or $ yarn add https://github.com/cinder92/react-native-get-music-files.git

iOS

  1. Add in info.plist following permission
<key>NSAppleMusicUsageDescription</key>
<string>This permission is not needed by the app, but it is required by an underlying API. If you see this dialog, contact us.</string>
  1. Add MediaPlayer.framework under build settings in Xcode
  2. Ensure all your music files are sync from a computer to a real iPhone device (this package does not work in simulators)

Android

  1. Navigate to android/app/src/main/AndroidManifest.xml and ensure to add this permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/> <-- Add this for Android 13 and newer versions

Before usage

As this package needs permissions from the device, please ensure that you asked for permissions before run any of this package functions.

Constants

SortSongFields {
    TITLE, DURATION, ARTIST, GENRE, ALBUM
}

SortSongOrder {
    ASC, DESC
}

Usage


import { getAll, getAlbums, searchSongs, SortSongFields, SortSongOrder } from "react-native-get-music-files";


const songsOrError = await getAll({
    limit: 20,
    offset: 0,
    coverQuality: 50,
    minSongDuration: 1000,
    sortBy: SortSongFields.TITLE,
    sortOrder: SortSongOrder.DESC,
});

// error 
if (typeof songsOrError === 'string') {
    // do something with the error
    return;
}

const albumsOrError = await getAlbums({
    limit: 10,
    offset: 0,
    coverQuality: 50,
    artist: 'Rihanna',
    sortBy: SortSongFields.ALBUM,
    sortOrder: SortSongOrder.DESC,
});

// error 
if (typeof albumsOrError === 'string') {
    // do something with the error
    return;
}

const resultsOrError = await searchSongs({
    limit: 10,
    offset: 0,
    coverQuality: 50,
    searchBy: '...',
    sortBy: SortSongFields.DURATION,
    sortOrder: SortSongOrder.DESC,
});

// error 
if (typeof resultsOrError === 'string') {
    // do something with the error
    return;
}

MusicFiles returns an array of objects where you can loop, something like this.

[
  {
    title : "La danza del fuego",
    author : "Mago de Oz",
    album : "Finisterra",
    genre : "Folk",
    duration : 209120,
    cover : "data:image/jpeg;base64, ....",
    url : "/sdcard/0/la-danza-del-fuego.mp3"
  }
]

Return Types

  • Album

    Type: Object

    | property | type | description | |---------------: |:--------: |------------------------------- | | album | string | album name | | artist | string | author | | cover | string | base64 of the artwork | | numberOfSongs | number | number of songs in this album |

  • Song

    | property | type | description | |--------------- |-------- |------------------------------- | | title | string | title | | artist | string | artist | | album | string | album name | | duration | string | duration in ms | | genre | string | genre | | cover | string | base64 of the artwork | | url | string | path of the song |

Methods

  • getAlbums

    async getAlbums(options) → {Promise<Album[] | string>}

    • options

      Type: Object

      | property | type | description | |--------------- |-------- |------------------------------- | | artist | string | required | | limit | number | optional | | offset | number | required if limit set | | coverQuality | number | optional | | sortBy | string | optional | | sortOrder | string | optional |

    • returns

      Type: Albums Error: string

  • getAll

    async getAll(options) → {Promise<Song[] | string>}

    • options

      Type: Object

      | property | type | description | |--------------- |-------- |------------------------------- | | limit | number | optional | | offset | number | required if limit set | | coverQuality | string | optional | | minSongDuration | number | optional | | sortBy | string | optional | | sortOrder | string | optional |

    • returns

      Type: Song Error: string

  • searchSongs

    async searchSongs(options) → { Promise<Song[] | string> }

    • options

      Type: Object

      | property | type | description | |--------------- |-------- |------------------------------- | | searchBy | string | required | | limit | number | optional | | offset | number | required if limit set | | coverQuality | number | optional | | sortBy | string | optional | | sortOrder | string | optional |

    • returns Type: Song Error: string

Usage:

example app

Version Changes

2.2

  • [x] Android & iOS compatible
  • [x] Retro-compat turbo module
  • [x] Limit & offset to paginate results
  • [x] Compatible with https://github.com/zoontek/react-native-permissions

PR are welcome!