Josias1997 / expo-music-library

Expo Music Library Package - Retrieve songs artworks, albums, artists, genres and songs folders from device's storage
2 stars 1 forks source link

Expo Music Library

npm License

expo-music-library is an Expo native module that enables you to read and retrieve audio files, albums, album audio, folders, and genres in your React Native applications. This library is designed to work on both Android and iOS platforms.

Supported Platforms

Platform Android iOS Device iOS Simulator Web Expo Go
Supported

Installation

Prerequisites

Make sure you have a React Native project set up with Expo. If not, you can create one by running:

npx create-expo-app MyApp

Installing the Module

To install expo-music-library, run:

yarn add expo-music-library

or

npm add expo-music-library

Platform-Specific Configuration

iOS
1.  Permissions:

Add the following keys to your Info.plist file to request the necessary permissions:

<key>NSAppleMusicUsageDescription</key>
<string>We need access to your music library to retrieve audio files.</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need access to your microphone to record audio.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library to manage music artwork.</string>
2.  Pod Installation:

Run the following command to install the necessary CocoaPods:

cd ios && pod install
Android
1.  Permissions:

Add the following permissions to your AndroidManifest.xml:

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

Usage

Here’s a basic example of how to use expo-music-library:

import {
    getAlbumsAsync,
    getArtistsAsync,
    getGenresAsync,
    getFolderAssetsAsync,
    getAssetsAsync,
    getAlbumAssetsAsync,
    getGenreAssetsAsync,
    requestPermissionsAsync,
    getPermissionsAsync
} from 'expo-music-library';

async function loadMusicData() {
    // Request permissions
    const permissions = await requestPermissionsAsync();
    console.log('Permissions:', permissions);

    // Get current permissions
    const currentPermissions = await getPermissionsAsync();
    console.log('Current Permissions:', currentPermissions);

    // Get all albums
    const albums = await getAlbumsAsync();
    console.log('Albums:', albums);

    // Get all artists
    const artists = await getArtistsAsync();
    console.log('Artists:', artists);

    // Get all genres
    const genres = await getGenresAsync();
    console.log('Genres:', genres);

    // Get assets in a specific folder by ID
    const folderAssets = await getFolderAssetsAsync('folderId');
    console.log('Folder Assets:', folderAssets);

    // Get all assets with custom options
    const assets = await getAssetsAsync({ first: 10, mediaType: ['audio'] });
    console.log('Assets:', assets);

    // Get assets from a specific album
    const albumAssets = await getAlbumAssetsAsync('albumName');
    console.log('Album Assets:', albumAssets);

    // Get assets from a specific genre only for android
    const genreAssets = await getGenreAssetsAsync('genreId');
    console.log('Genre Assets:', genreAssets);
}

loadMusicData();

Functions

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

If you have any questions or issues, feel free to open an issue on the GitHub repository or contact the author directly:

This README was generated to help you get started with the expo-music-library module. Enjoy coding!

Summary:

This README.md should provide comprehensive guidance for anyone using your expo-music-library module, whether they are working on Android or iOS.