1.5.3 • Published 3 years ago

react-native-audio-helper v1.5.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

React native audio helper

A library for audio application.

Table of content

Demo

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 nameTypeDescriptionDefault value
listSoundsISoundFileList sounds we will play[]
timeRatenumberThis is used for methods increaseTime, decreaseTime => increase or decrease current time by timeRate (seconds)15 (seconds)
isLogStatusbooleanLog current status of player using console.logfalse

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 nameTypeDescription
secondsnumberChange current time to seconds

Set speed

Change player's speed

player.setSpeed(1.25);
Param nameTypeDescriptionDefault value
speednumberChange 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 variableTypeDescriptionDefault value
isShufflebooleanIs shuffle or notfalse

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 variableTypeDescriptionDefault value
isLoopbooleanIs loop current audio or notfalse

Mute

Mute player

player.mute(); // isMuted=true

Unmute

Unmute player

player.unmute() // isMuted=false

Set volume

player.setVolume(50); // volume=50%
Param nameTypeDescriptionDefault value
volumenumberChange current volume to volume (volume >= 0% and volume <= 100%)100%

Variables

Variable nameTypeDescriptionDefault value
statusAudioStatusTypeCurrent player's status'loading'
durationnumberDuration of current audio (seconds)
currentTimenumberCurrent time of current audio (seconds)0
durationStringstringDuration string with format 'hh:mm:ss'
currentTimeStringstringCurrent time string with format 'hh:mm:ss'
currentAudioNamestringCurrent audio name''
isDisabledButtonPlaybooleanDisabled button play or not
isDisabledButtonPausebooleanDisabled button pause or not
isDisabledButtonStopbooleanDisabled button stop or not
timeRatenumberThis is used for methods increaseTime, decreaseTime => increase or decrease current time by timeRate (seconds)15 (seconds)
speednumberChange current speed to speed (speed > 0.0 and speed <= 2.0)1
isShufflebooleanIs shuffle or notfalse
isLoopbooleanIs loop current audio or notfalse
isMutedbooleanIs mute player or notfalse
volumenumberChange current volume to volume (volume >= 0% and volume <= 100%)100%
1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago