Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cinder92/react-native-get-music-files
React Native package to get music files from local and sd for iOS and Android
https://github.com/cinder92/react-native-get-music-files
Last synced: about 2 months ago
JSON representation
React Native package to get music files from local and sd for iOS and Android
- Host: GitHub
- URL: https://github.com/cinder92/react-native-get-music-files
- Owner: cinder92
- License: mit
- Created: 2017-01-19T01:32:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T12:44:46.000Z (9 months ago)
- Last Synced: 2024-05-07T05:21:34.527Z (8 months ago)
- Language: Kotlin
- Homepage:
- Size: 1.5 MB
- Stars: 124
- Watchers: 5
- Forks: 63
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-react-native-native-modules - react-native-get-music-files ★14
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
```
NSAppleMusicUsageDescription
This permission is not needed by the app, but it is required by an underlying API. If you see this dialog, contact us.
```
2. Add MediaPlayer.framework under build settings in Xcode
3. 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
```<-- 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
```js
SortSongFields {
TITLE, DURATION, ARTIST, GENRE, ALBUM
}SortSongOrder {
ASC, DESC
}
```## Usage
```jsimport { 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.
```js
[
{
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
* AlbumType: 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}`* 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}`
* 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 }`
* 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](https://github.com/cinder92/react-native-get-music-files/tree/master/example)
# 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!