1.2.2 • Published 5 years ago

react-native-imusic v1.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-native-imusic

React-native-imusic is a music player component similar to HTML5 Audio, based on react-native-sound.

react-native-imusic 是一个类似 HTML5 Audio 的音乐播放组件,其底层基于 react-native-sound。中文说明 -> 点这里

npm.io

Installation

yarn add react-native-imusic
# or
npm install --save react-native-imusic

link:

react-native link react-native-sound

modify the code in android/build.gradle:

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Usage

import IMusic from 'react-native-imusic';

<IMusic
    source={{ uri: song.url }}
    play={play}
    onProgress={d => {
        // ...
    }}
/>

Example

Please check example code.

Props

nametypedefaultdescription
sourceobject{}music source, @required.
playboolfalsewhether to play music, @required.
loopboolfalsewhether to loop play music.
autoPlayboolfalseWhether to play automatically after loading is complete.
preloadboolfalseWhether to preload.
initSeeknumber0Initialize playback position.
progressUpdateIntervalnumber500Progress Update Interval.

event:

nametypedefaultdescription
onProgressfunctiond => dmusic playback progress event.
onLoadStartfunctione => efires when the music is loadedstart.
onLoadfunctiond => dfires when the music is loaded.
onPlayfunctione => efires when the music plays.
onPausefunctione => efires when the music is paused.
onEndfunctione => efires when the music ends.
onErrorfunctione => efires when an error occurs in music playback/loading.

onProgress callback param data:

{
    currentTime: 22.40,
    duration: 183.32,
    volume: 1,
    percent: 12.22,
}

onLoad callback param data:

{
    currentTime: 0,
    duration: 183.32,
    volume: 1,
    percent: 0,
}

Method

nametypedescription
isPlayfunction
seekfunction(time: number)
volumefunction(num?: number)
reLoadfunction

Change log