0.1.0 • Published 4 months ago

react-native-background-audio-record v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-native-background-audio-record

This library provides the feature to record when in the background on Android.

This Library use FOREGROUND_SERVICE of Android to provide a stable recording function in the background and when the app is turned off. That is why Push Notification is sent at the same time as recording. Users can edit the title and content of the Push Notification.

Screenshot

Install

npm install react-native-background-audio-record

Permissions

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Method

MethodDescriptionParam
startRecord()start recording with FOREGROUND_SERVICE and show push notificationpath?:string audioConfig? notificationConfig?
stopRecord()stop recording (push notification will be closed)
playAudio()play recording audio if you don't pass path then will play default path filepath? : string
stopAudio()stop playing audio file

Examples

you can also check code in Example

import React from 'react';
import { Button, StyleSheet, View } from 'react-native';
import BgRecorder, {
  AudioSource,
  OutputFormat,
  AudioEncoder,
  type NoticationConfig,
  type AudioConfig,
} from 'react-native-background-audio-record';
import RNFS from 'react-native-fs';

const path = `${RNFS.DownloadDirectoryPath}/sound.m4a`;

const notificationConfig: NoticationConfig = {
  channelName: 'name',
  contentText: 'text',
  contentTitle: 'title',
};

const audioConfig: AudioConfig = {
  audioSource: AudioSource.MIC,
  outputFormat: OutputFormat.DEFAULT,
  audioEncoder: AudioEncoder.AAC,
  audioSamplingRate: 48000,
  audioEncodingBitRate: 128000,
  audioChannels: 2,
};
// ---------   recordOnBackground   ---------//
// default path is
// AOS : {cacheDir}/sound.m4a
const recorder = BgRecorder.recorder();

recorder.startRecord({ path, notificationConfig, audioConfig });
recorder.stopRecord();
recorder.startAudio(path);
recorder.stopAudio();
0.1.0

4 months ago

0.0.4

5 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago