# react-amai-music-player

> Maybe the best beautiful HTML5 responsive player component for react

Latest version **1.1.1** (published 2020-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-amai-music-player
pnpm add react-amai-music-player
yarn add react-amai-music-player
bun add react-amai-music-player
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2020-01-31 |
| First published | 2020-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 767 |
| Author | Jinke.Li |
| Maintainers | maxbaluev |
| Keywords | react, reactjs, player, music, audio, react-player, react-amai-music-player, react-music-player, react-audio-player, cd-player, music-player, audio-player, component |

## Links

- npm: https://www.npmjs.com/package/react-amai-music-player
- Repository: https://github.com/lijinke666/react-music-player
- Homepage: https://lijinke666.github.io/react-music-player
- Issues: https://github.com/lijinke666/react-music-player/issues
- npm.io page: https://npm.io/package/react-amai-music-player

## Dependencies (9)

- [is-mobile](https://npm.io/package/is-mobile.md) ^2.1.0
- [rc-slider](https://npm.io/package/rc-slider.md) ^8.7.1
- [rc-switch](https://npm.io/package/rc-switch.md) ^1.9.0
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [downloadjs](https://npm.io/package/downloadjs.md) ^1.4.7
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [react-draggable](https://npm.io/package/react-draggable.md) ^3.3.2
- [react-drag-listview](https://npm.io/package/react-drag-listview.md) ^0.1.6
- [eslint-config-airbnb-base](https://npm.io/package/eslint-config-airbnb-base.md) ^14.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-01-31

## README

<p align="center">
  <img alt="logo" src="https://github.com/lijinke666/react-music-player/blob/master/assetsImg/logo.png" width="100" max-width="100%">
</p>

<h1 align="center">
react-amai-music-player
</h1>

<h4 align="center">
:musical_note: Maybe the best beautiful HTML5 responsive player component for react : )
</h4>

<p align="center">
  <a href="https://www.npmjs.com/package/react-amai-music-player" title="npm">
    <img src="https://img.shields.io/npm/dm/react-amai-music-player.svg?style=flat-square" alt="npm">
  </a>
  <a href="https://www.npmjs.com/package/react-amai-music-player" title="npm">
    <img src="https://img.shields.io/npm/l/react-amai-music-player.svg?style=flat-square" alt="npm">
  </a>
   <a href="https://travis-ci.org/lijinke666/react-music-player" title="Build Status">
    <img src="https://travis-ci.org/lijinke666/react-music-player.svg?branch=master" alt="Build Status">
  </a>
   <a href="https://badge.fury.io/js/react-amai-music-playerr" title="npm">
    <img src="https://img.shields.io/npm/v/react-amai-music-player.svg?style=flat-square" alt="npm version">
  </a>
  <a href="https://codecov.io/gh/lijinke666/react-music-player">
    <img src="https://codecov.io/gh/lijinke666/react-music-player/branch/master/graph/badge.svg" />
  </a>
     <a href="https://app.netlify.com/sites/react-amai-music-player/deploys" title="Netlify Status">
    <img src="https://api.netlify.com/api/v1/badges/2a5d8639-9d2a-46ee-a504-10b7846a57e4/deploy-status" alt="Coverage Status">
  </a>
</p>



<p align="center">
  <a href="https://github.com/lijinke666/react-music-player/blob/master/CN.md">
    中文文档 (Chinese documentation)
  </a>
</p>

## Installation

using `yarn` :

```
yarn add react-amai-music-player
```

using `npm` :

```
npm install react-amai-music-player --save
```

## Screenshots

> mini mode <br/>

> ![mini mode](https://github.com/lijinke666/react-music-player/blob/master/assetsImg/mini.png)

> Light Theme <br/>

![light theme](https://github.com/lijinke666/react-music-player/blob/master/assetsImg/light-theme.png)

> Dark Theme <br/>

![dark theme](https://github.com/lijinke666/react-music-player/blob/master/assetsImg/dark-theme.png)

> mobile <br/>

![mobile](https://github.com/lijinke666/react-music-player/blob/master/assetsImg/mobile.jpg)

## Example

> live example :
- [https://lijinke666.github.io/react-music-player/](https://lijinke666.github.io/react-music-player/)
- [https://react-amai-music-player.netlify.com/](https://react-amai-music-player.netlify.com/)

> practical application : [Jinke.Li's House](http://www.lijinke.cn/)

> local example : [http://localhost:8081/](http://localhost:8081/)

[Source Code](https://github.com/lijinke666/react-music-player/blob/master/example/example.js)

## Usage

```jsx
import React from "react";
import ReactDOM from "react-dom";
import ReactJkMusicPlayer from "react-amai-music-player";
import "react-amai-music-player/assets/index.css";

ReactDOM.render(
  <ReactJkMusicPlayer {...options} />,
  document.getElementById("root")
);
```

## API

| Name              | Type                  | Default           | Description |
| ------------ | ------- | ------- | ----------- |
| className         | `string`              | `-`               | Additional CSS class for the root DOM node                                                                                           |
| audioLists        | `object[]`            | `-`               | [detail](#AudioList)  |
| theme             | `string`              | `dark`            | color of the music player theme  `dark` | `light`                                                                                                    |
| defaultPosition   | `object`              | `{top:0,left:0}`  | audio controller initial position with `left,top,right,and bottom` |
| playModeText | `object` | {order: "order",orderLoop: "orderLoop",singleLoop: "singleLoop",shufflePlay:"shufflePlay"}` | play mode text config of the audio player |
| playModeShowTime          | `number`  | `600`            |  play mode toggle show time (ms) |
| bounds          | `object`,`number`  | `body`            |  specifies movement boundaries. Accepted values:  `parent` restricts movement within the node's offsetParent    (nearest node with position relative or absolute), or a selector, restricts movement within the targeted node An object with `left, top, right, and bottom` properties. These indicate how far in each direction the draggable can be moved. |
| preload          | `boolean`,`string`  | `false`            |  Whether to load audio immediately after the page loads. can be set to `auto|metadata|none` `true|false` if `preload=true` preload="auto" |
| remember          | `boolean`  | `false`            |  The next time you access the player, do you keep the last state  |
| glassBg          | `boolean`  | `false`            |  Whether the player's background displays frosted glass effect |
| remove          | `boolean`  | `true`            |  The Audio Can be deleted  |
| defaultPlayIndex          | `number`  | `0`            |  Default play index of the audio player  |
| playIndex          | `number`  | `0`            |  play index of the audio player  |
| openText          | `string`  | `open`            | audio controller open text  |
| closeText         | `string`  | `close`           | audio controller close text |
| panelTitle        | `string`  | `PlayList`        | audio list panel title |
| notContentText    | `string`  | `no music`        | audio list panel show text of the playlist has no songs  |
| checkedText       | `string`  | `-`               | audio theme switch checkedText    |
| unCheckedText     | `string`  | `-`               | audio theme switch unCheckedText  |
| defaultPlayMode   | `string`              | `order`           | default play mode of the audio player options can be set to `order`,`orderLoop`,`singleLoop`,`shufflePlay` or omitted                |
| mode              | `string`              | `mini`            | audio theme switch checkedText can be set to `mini`,`full` or omitted  |
| once              | `boolean`             | `false`           | The default audioPlay handle function will be played again after each pause, If you only want to trigger it once, you can set 'true' |
| autoPlay          | `boolean`             | `true`            | Whether the audio is played after loading is completed.  |
| toggleMode        | `boolean`             | `true`            | Whether you can switch between two modes, full => mini or mini => full   |
| drag              | `boolean`             | `true`            | audio controller is can be drag of the "mini" mode   |
| seeked            | `boolean`             | `true`            | Whether you can drag or click the progress bar to play in the new progress.  |
| showMiniModeCover | `boolean`             | `true`            | audio cover is show of the "mini" mode |
| showMiniProcessBar | `boolean`             | `false`            | audio progress circle bar is show of the "mini" mode |
| showProgressLoadBar | `boolean`             | `true`            | Displays the audio load progress bar. |
| showPlay | `boolean`             | `true`            | play button display of the audio player panel |
| showReload | `boolean`             | `true`            | reload button display of the audio player panel  |
| showDownload | `boolean`             | `true`            | download button display of the audio player panel  |
| showPlayMode | `boolean`             | `true`            | play mode toggle button display of the audio player panel |
| showThemeSwitch | `boolean`             | `true`            | theme toggle switch display of the audio player panel |
| showLyric | `boolean`             | `false`            | audio lyric button display of the audio player panel |
| lyricClassName | `string`             | `-`            | audio lyric class name |
| emptyLyricPlaceholder | `string`             | `-`            | audio lyric empty lyric placeholder |
| extendsContent | `array`             | `-`            | Extensible custom content like `[<button>button1</button>,<button>button2</button>]` |
| controllerTitle | `string`             | `<FaHeadphones/>`            | audio controller title |
| defaultVolume | `number`             | `100`            | default volume of the audio player , range `0`-`100` |
| loadAudioErrorPlayNext | `boolean`             | `true`            | Whether to try playing the next audio when the current audio playback fails |
| onAudioDownload | `function(audioInfo)` | `-`            | audio is downloaded handle |
| onAudioPlay     | `function(audioInfo)` | `-`            | audio play handle |
| onAudioPause    | `function(audioInfo)` | `-`          | audio pause handle |
| onAudioSeeked   | `function(audioInfo)` | `-`          | When the user has moved/jumped to a new location in audio handle |
| onAudioVolumeChange   | `function(audioInfo)` | `-`          |  When the volume has changed handle min = 0.0 max = 1.0  |
| onAudioEnded   | `function(audioInfo)` | `-`          |  The single song is ended handle |
| onAudioAbort   | `function(audioInfo)` | `-`          |  audio load abort The target event like {...,audioName:xx,audioSrc:xx,playMode:xx}|
| onAudioProgress   | `function(audioInfo)` | `-`          |  audio play progress handle |
| onAudioLoadError   | `function(audioInfo)` | `-`          |  audio load failed error handle |
| onAudioReload  | `function(audioInfo)` | `-`          |  audio reload handle |
| onAudioListsChange  | `function(currentPlayIndex,audioLists,audioInfo)` | `-`          |  audio lists change handle |
| onAudioPlayTrackChange  | `function(currentPlayIndex,audioLists,audioInfo)` | `-`          |  audio current play track change handle |
| onAudioPlayModeChange  | `function(playMode)` | `-`          |  play mode change handle |
| onAudioListsPanelChange  | `function(panelVisible)` | `-`          |  audio lists panel change handle |
| onThemeChange  | `function(theme)` | `-`          |  theme change handle |
| onModeChange  | `function(mode)` | `-`          |  mode change handle |
| onAudioListsDragEnd  | `function(fromIndex,endIndex)` | `-`          |  audio lists drag end handle |
| onAudioLyricChange  | `function(lineNum, currentLyric)` | `-`          |  audio lyric change handle |
| getContainer  | `() => HTMLElement` \| ` Selectors ` | `document.body`          |  Return the mount node for Music player |


## Development

```
git clone https://github.com/lijinke666/react-music-player.git
yarn | npm install
yarn start | npm start
open `http://localhost:8081/`
```

## Test case

```
npm run test
```

## AudioList

> Like This

```ts
interface ReactJkMusicPlayerAudioList {
  name: string | React.ReactNode,
  singer?: string | React.ReactNode,
  cover: string,
  musicSrc: string | () => Promise<string>,
  lyric?: string,
}>
```

## AudioInfo

> Like This

```ts
interface ReactJkMusicPlayerAudioInfo {
  cover: string,
  currentTime: number,
  duration: number,
  ended: boolean,
  musicSrc: string,
  muted: boolean,
  name: string,
  networkState: number,
  paused: boolean,
  played: any,
  readyState: number,
  startDate: any
  volume: number,
  lyric: string,
}
```

## Properties

```ts
interface ReactJkMusicPlayerProps {
  audioLists: Array<ReactJkMusicPlayerAudioList>,
  theme?: ReactJkMusicPlayerTheme,
  mode?: ReactJkMusicPlayerMode,
  defaultPlayMode?: ReactJkMusicPlayerPlayMode
  drag?: boolean,
  seeked?: boolean,
  autoPlay?: boolean,
  playModeText?: {
    order: string | React.ReactNode,
    orderLoop: string | React.ReactNode,
    singleLoop: string | React.ReactNode,
    shufflePlay: string | React.ReactNode
  },
  panelTitle?: string | React.ReactNode,
  closeText?: string | React.ReactNode,
  openText?: string | React.ReactNode,
  notContentText?: string | React.ReactNode,
  controllerTitle?: string | React.ReactNode,
  defaultPosition?: {
    top: number | string,
    left: number | string,
    right: number | string,
    bottom: number | string
  },
  onAudioPlay?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioPause?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioEnded?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioAbort?: (data: any) => void,
  onAudioVolumeChange?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioLoadError?: (data: any) => void,
  onAudioProgress?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioSeeked?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioDownload?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onAudioReload?: (audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onThemeChange?: (theme: ReactJkMusicPlayerTheme) => void,
  onAudioListsChange?: (currentPlayId: string, audioLists: Array<ReactJkMusicPlayerAudioList>, audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  onPlayModeChange?: (playMode: ReactJkMusicPlayerPlayMode) => void,
  onModeChange?: (mode: ReactJkMusicPlayerMode) => void,
  onAudioListsPanelChange?: (panelVisible: boolean) => void,
  onAudioPlayTrackChange?: (fromIndex: number, endIndex: number) => void,
  onAudioListsDragEnd?: (currentPlayId: string, audioLists: Array<ReactJkMusicPlayerAudioList>, audioInfo: ReactJkMusicPlayerAudioInfo) => void,
  showDownload?: boolean,
  showPlay?: boolean,
  showReload?: boolean,
  showPlayMode?: boolean,
  showThemeSwitch?: boolean,
  showMiniModeCover?: boolean,
  toggleMode?: boolean,
  once?: boolean,
  extendsContent?: Array<React.ReactNode | string>,
  checkedText?: string | React.ReactNode,
  unCheckedText?: string | React.ReactNode,
  defaultVolume?: number,
  playModeShowTime?: number,
  bounds?: string | React.ReactNode,
  showMiniProcessBar?: boolean,
  loadAudioErrorPlayNext?: boolean,
  preload?: boolean | "auto" | "metadata" | "none",
  glassBg?: boolean,
  remember?: boolean,
  remove?: boolean,
  defaultPlayIndex?: number,
  playIndex?: number,
  lyricClassName?: string,
  emptyLyricPlaceholder?: string | React.ReactNode,
  showLyric?: boolean,
  getContainer?: () => HTMLElement
}
```

## License

[MIT](https://github.com/lijinke666/react-music-player/blob/master/LICENCE)

---
_Source: https://npm.io/package/react-amai-music-player · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
