react-native-audios

0.0.5 • Public • Published

npm npm npm

Record and play audio in iOS or Android React Native apps.

整合了react-native-audioreact-native-sound 修复了这两个库的一些兼容问题,ios端增加了转码功能,可以支持录播amr格式。

Installation

npm install react-native-audios --save

Then link it automatically using:

react-native link react-native-audios

Usage

record

import { AudioRecorder, AudioUtils, Sound } from 'react-native-audios';
let audioPath = AudioUtils.DocumentDirectoryPath + '/test.amr',

AudioRecorder.prepareRecordingAtPath(audioPath, {
	SampleRate: 22050,
	Channels: 1,
	AudioQuality: "Low",
	AudioEncoding: "amr",
	AudioEncodingBitRate: 32000
});

playing audio

var sound = new Sound(this.state.audioPath, '', (error) => {
	if (error) {
		console.log('failed to load the sound', error);
	}
});

sound.play((success) => {
	if (success) {
		console.log('successfully finished playing');
	} else {
		console.log('playback failed due to audio decoding errors');
	}
});

See Example for detail

THANKS

Package Sidebar

Install

npm i react-native-audios

Weekly Downloads

2

Version

0.0.5

License

ISC

Last publish

Collaborators

  • liuyanhongwl