@gauch_99/react-native-audio-files
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

react-native-audio-files

This package provides functionality to retrieve all audio files stored on an Android device. With this module, you can easily access and manage audio files within your React Native application.

Installation

npm install react-native-audio-files

Usage

import { fetchAudioFiles } from 'react-native-audio-files';

const audioFiles = await fetchAudioFiles();

Or Follow Basic Example:

import { fetchAudioFiles } from 'react-native-audio-files';

const [audioFiles, setAudioFiles] = useState([]);

useEffect(() => {
  const getAudioFiles = async () => {
    return await fetchAudioFiles();
  };
  getAudioFiles().then((result) => {
    setAudioFiles(result);
  });
}, []);

return (
  <View>
    {audioFiles?.map((element, index) => {
      return (
        <View key={index}>
          <Text>{element?.title}</Text>
        </View>
      );
    })}
  </View>
);

List of keys available:

Key Description Type
addedDate Added Date Time of the Audio File String
album Album of the Audio File String
artist Artist of the Audio File String
audioUrl Path of the Audio File String
duration Duration of the Audio File Integer
id Unique Id of the Audio File String
imageUrl Image of the Audio File String
size Size of the Audio File String
title Title of the Audio File String

Note:

  1. addedDate is of type UNIX Timestamp, to convert it into the required time format of YYYY-MM-DD HH:MM:SS
const formattedDateTime = new Date(addedDate * 1000).toISOString().slice(0, 19).replace('T', ' ');
  1. Make sure you have permissions granted from User for Reading Storage according to the Android Versions or you wont be able to fetch files.
Example: <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Contributing

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

License

MIT

Package Sidebar

Install

npm i @gauch_99/react-native-audio-files

Weekly Downloads

2

Version

1.2.1

License

MIT

Unpacked Size

28.2 kB

Total Files

19

Last publish

Collaborators

  • gauch_99