4.3.7 • Published 5 years ago

react-blessedness-music-player v4.3.7

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

Installation

using yarn :

yarn add react-jinke-music-player

using npm :

npm install react-jinke-music-player --save

Screenshots

mini mode

mini mode

Light Theme

light theme

Dark Theme

dark theme

mobile

mobile

Example

live example : https://lijinke666.github.io/react-music-player/

practical application : Jinke.Li's House

local example : http://localhost:8081/

Source Code

Usage

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

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

API

NameTypeDefaultDescription
classNamestring-Additional CSS class for the root DOM node
audioListsobject[]-detail
themestringdarkcolor of the music player theme darklight
defaultPositionobject{top:0,left:0}audio controller initial position with left,top,right,and bottom
playModeTextobject{order: "order",orderLoop: "orderLoop",singleLoop: "singleLoop",shufflePlay:"shufflePlay"}` | play mode text config of the audio player
playModeShowTimenumber600play mode toggle show time (ms)
boundsobject,numberbodyspecifies 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.
preloadboolean,stringfalseWhether to load audio immediately after the page loads. can be set to auto|metadata|none true|false if preload=true preload="auto"
rememberbooleanfalseThe next time you access the player, do you keep the last state
glassBgbooleanfalseWhether the player's background displays frosted glass effect
removebooleantrueThe Audio Can be deleted
defaultPlayIndexnumber0Default play index of the audio player
playIndexnumber0play index of the audio player
openTextstringopenaudio controller open text
closeTextstringcloseaudio controller close text
panelTitlestringPlayListaudio list panel title
notContentTextstringno musicaudio list panel show text of the playlist has no songs
checkedTextstring-audio theme switch checkedText
unCheckedTextstring-audio theme switch unCheckedText
defaultPlayModestringorderdefault play mode of the audio player options can be set to order,orderLoop,singleLoop,shufflePlay or omitted
modestringminiaudio theme switch checkedText can be set to mini,full or omitted
oncebooleanfalseThe default audioPlay handle function will be played again after each pause, If you only want to trigger it once, you can set 'true'
autoPlaybooleantrueWhether the audio is played after loading is completed.
toggleModebooleantrueWhether you can switch between two modes, full => mini or mini => full
dragbooleantrueaudio controller is can be drag of the "mini" mode
seekedbooleantrueWhether you can drag or click the progress bar to play in the new progress.
showMiniModeCoverbooleantrueaudio cover is show of the "mini" mode
showMiniProcessBarbooleanfalseaudio progress circle bar is show of the "mini" mode
showProgressLoadBarbooleantrueDisplays the audio load progress bar.
showPlaybooleantrueplay button display of the audio player panel
showReloadbooleantruereload button display of the audio player panel
showDownloadbooleantruedownload button display of the audio player panel
showPlayModebooleantrueplay mode toggle button display of the audio player panel
showThemeSwitchbooleantruetheme toggle switch display of the audio player panel
showLyricbooleanfalseaudio lyric button display of the audio player panel
lyricClassNamestring-audio lyric class name
emptyLyricPlaceholderstring-audio lyric empty lyric placeholder
extendsContentarray-Extensible custom content like [<button>button1</button>,<button>button2</button>]
controllerTitlestring<FaHeadphones/>audio controller title
defaultVolumenumber100default volume of the audio player , range 0-100
loadAudioErrorPlayNextbooleantrueWhether to try playing the next audio when the current audio playback fails
onAudioDownloadfunction(audioInfo)-audio is downloaded handle
onAudioPlayfunction(audioInfo)-audio play handle
onAudioPausefunction(audioInfo)-audio pause handle
onAudioSeekedfunction(audioInfo)-When the user has moved/jumped to a new location in audio handle
onAudioVolumeChangefunction(audioInfo)-When the volume has changed handle min = 0.0 max = 1.0
onAudioEndedfunction(audioInfo)-The single song is ended handle
onAudioAbortfunction(audioInfo)-audio load abort The target event like {...,audioName:xx,audioSrc:xx,playMode:xx}
onAudioProgressfunction(audioInfo)-audio play progress handle
onAudioLoadErrorfunction(audioInfo)-audio load failed error handle
onAudioReloadfunction(audioInfo)-audio reload handle
onAudioListsChangefunction(currentPlayIndex,audioLists,audioInfo)-audio lists change handle
onAudioPlayTrackChangefunction(currentPlayIndex,audioLists,audioInfo)-audio current play track change handle
onAudioPlayModeChangefunction(playMode)-play mode change handle
onAudioListsPanelChangefunction(panelVisible)-audio lists panel change handle
onThemeChangefunction(theme)-theme change handle
onModeChangefunction(mode)-mode change handle
onAudioListsDragEndfunction(fromIndex,endIndex)-audio lists drag end handle
onAudioLyricChangefunction(lineNum, currentLyric)-audio lyric change handle

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

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

AudioInfo

Like This

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

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,
}

License

MIT