An open API service indexing awesome lists of open source software.

https://github.com/oovui/audio-player-react

just a simple audio player based React
https://github.com/oovui/audio-player-react

audio audioplayer player react react-audio-player wechat-audio-player

Last synced: about 1 year ago
JSON representation

just a simple audio player based React

Awesome Lists containing this project

README

          

# audio-player-react

> just a simple audio player based React

[![npm](https://img.shields.io/npm/v/@oovui/audio-player-react.svg)](https://www.npmjs.com/package/@oovui/audio-player-react)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm i @oovui/audio-player-react
```
## Preview

## Simple Usage

> Just `url` props is Required

```jsx
import React, { Component } from 'react'

import OAudioPlayer from '@oovui/audio-player-react'

class App extends Component {
render () {
return (

)
}
}
```

## Advance Usage

```jsx
import React, { Component } from 'react'
import OAudioPlayer from '@oovui/audio-player-react'
const mediaUrl = require('./assets/nideyangzi.mp3');
const anthorMediaUrl = require('./assets/sound.mp3');

export default class App extends Component {

constructor(props){
super(props);
this.audioPlayerRef = React.createRef();
}
state = {
url: ''
}

componentDidMount() {
setTimeout(() => {
this.setState({
url: mediaUrl
})
}, 800);
}

onPlayingHandle() {
console.log("onPlayingHandle:audio start play")
}

onPauseHandle(){
console.log("onPauseHandle:audio pause")
}

doPlay=()=>{
this.audioPlayerRef.current.audioPlay();
}

doPause=()=>{
this.audioPlayerRef.current.audioPause();
}

doPlayAndPause=()=>{
this.audioPlayerRef.current.audioPlayPause();
}

togglePlay=()=>{
this.setState({
url: anthorMediaUrl
},function(){
this.doPlay();
})
}

render() {
const { url } = this.state;
return (



播放
暂停
播放和暂停
切歌

)
}
}
```

## Props

| Name | Type | Description |
| ---- | ---- | ----------- |
| **ref** | React.createRef() | get audio player Instance, can do Dom
| **url** | String | the audio player src(mp3), is `required`
| **title** | String | the audio player title
| **subtitle** | String | the audio player subtitle
| **pauseIcon** | String | the audio player pause icon
| **playingIcon** | String | the audio player playing icon
| **loop** | Boolean | default `false`, other value: `true`
| **preload** | String | default `metadata`, other value: `auto`、`none`
| **autoplay** | Boolean | default `false`, other value: `auto`、`none`

## Events
- playing
- pause

## Methods
- audioPlay()
- audioPause()
- audioPlayPause()

## Bootstrapped with create-react-library:
https://github.com/transitive-bullshit/create-react-library

## License

MIT © [https://github.com/oovui/audio-player-react](https://github.com/https://github.com/oovui/audio-player-react)