react-native-audio-helper
v1.5.3
Published
A library play audio based on react-native-sound
Downloads
4
Maintainers
Keywords
Readme
React native audio helper
A library for audio application.
Table of content
Demo
- Link youtube: https://www.youtube.com/watch?v=OfUqaofrcMw
- Link github: https://github.com/uit2712/RNPlaySound
Installation
Install react-native-sound
Link: https://github.com/zmxv/react-native-sound
npm install react-native-sound --save
react-native link react-native-sound
Install react-native-audio-helper
npm install react-native-audio-helper --save
Usage
import SoundPlayer from 'react-native-sound';
import { useAudioHelper } from './helpers/audio-helper';
function App() {
const player = useAudioHelper({
listSounds: [
{ path: 'blue_dream_cheel.mp3', name: 'Blue Dream - Cheel', basePath: SoundPlayer.MAIN_BUNDLE },
{ path: 'know_myself_patrick_patrikios.mp3', name: 'Know Myself - Patrick Patrikios', basePath: SoundPlayer.MAIN_BUNDLE },
{ path: require('./sounds/Play-Doh-meets-Dora_Carmen-Maria-and-Edu-Espinal.mp3'), name: 'Play Doh meets Dora - Carmen Maria and Edu Espinal', isRequired: true, },
{ path: 'https://raw.githubusercontent.com/uit2712/RNPlaySound/develop/sounds/Tropic%20-%20Anno%20Domini%20Beats.mp3', name: 'Tropic - Anno Domini Beats', },
],
timeRate: 15,
isLogStatus: true,
});
...
}
|Param name|Type|Description|Default value| |---|---|---|---| |listSounds|ISoundFile|List sounds we will play|[]| |timeRate|number|This is used for methods increaseTime, decreaseTime => increase or decrease current time by timeRate (seconds)|15 (seconds)| |isLogStatus|boolean|Log current status of player using console.log|false|
Methods
Play
Play current audio
player.play(); // player.status='play'
Pause
Pause current audio
player.pause(); // player.status='pause'
Stop
Stop current audio
player.stop(); // player.status='stop'
Next
Move to next audio
player.next(); // player.status='next'
Previous
Back to previous audio
player.previous(); // player.status='previous'
Increase time
Increase current time to next timeRate (seconds)
player.increaseTime();
Decrease time
Decrease current time to previous timeRate (seconds)
player.decreaseTime();
Seek to time
Change current time
player.seekToTime(15); // seconds
|Param name|Type|Description| |---|---|---| |seconds|number|Change current time to seconds|
Set speed
Change player's speed
player.setSpeed(1.25);
|Param name|Type|Description|Default value| |---|---|---|---| |speed|number|Change current speed to speed (speed > 0.0 and speed <= 2.0)|1|
Shuffle
Random next or previous audio index
player.shuffle(); // call odd time (2n+1 time, n>0) => isShuffle=true, call even time (2n time, n>0) => isShuffle=false
|Relative variable|Type|Description|Default value| |---|---|---|---| |isShuffle|boolean|Is shuffle or not|false|
Loop
Loop current audio
player.loop(); // call odd time (2n+1 time, n>0) => isLoop=true, call even time (2n time, n>0) => isLoop=false
|Relative variable|Type|Description|Default value| |---|---|---|---| |isLoop|boolean|Is loop current audio or not|false|
Mute
Mute player
player.mute(); // isMuted=true
Unmute
Unmute player
player.unmute() // isMuted=false
Set volume
player.setVolume(50); // volume=50%
|Param name|Type|Description|Default value| |---|---|---|---| |volume|number|Change current volume to volume (volume >= 0% and volume <= 100%)|100%|
Variables
|Variable name|Type|Description|Default value| |---|---|---|---| |status|AudioStatusType|Current player's status|'loading'| |duration|number|Duration of current audio (seconds)|| |currentTime|number|Current time of current audio (seconds)|0| |durationString|string|Duration string with format 'hh:mm:ss'|| |currentTimeString|string|Current time string with format 'hh:mm:ss'|| |currentAudioName|string|Current audio name|''| |isDisabledButtonPlay|boolean|Disabled button play or not|| |isDisabledButtonPause|boolean|Disabled button pause or not|| |isDisabledButtonStop|boolean|Disabled button stop or not|| |timeRate|number|This is used for methods increaseTime, decreaseTime => increase or decrease current time by timeRate (seconds)|15 (seconds)| |speed|number|Change current speed to speed (speed > 0.0 and speed <= 2.0)|1| |isShuffle|boolean|Is shuffle or not|false| |isLoop|boolean|Is loop current audio or not|false| |isMuted|boolean|Is mute player or not|false| |volume|number|Change current volume to volume (volume >= 0% and volume <= 100%)|100%|