Socket
Socket
Sign inDemoInstall

react-jinke-music-player

Package Overview
Dependencies
35
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-jinke-music-player

Maybe the best beautiful HTML5 responsive player component for react


Version published
Weekly downloads
1.2K
decreased by-13.03%
Maintainers
1
Install size
12.0 MB
Created
Weekly downloads
 

Readme

Source

logo

react-jinke-music-player

:musical_note: Maybe the best beautiful HTML5 responsive player component for react : )

npm npm Build Status npm version Coverage Status

中文文档

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 :

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 dark
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
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 | ReactNode | boolean | string-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
getContainer() => HTMLElement | Selectorsdocument.bodyReturn the mount node for Music player
getAudioInstance(instance: HTMLAudioElement) => void-get origin audio element instance , you can use it do everything
autoHiddenCoverbooleanfalseAuto hide the cover photo if no cover photo is available
onBeforeAudioDownload(audioInfo: ReactJkMusicPlayerAudioInfo) => Promise<TransformedDownloadAudioInfo>-transform download audio info before
clearPriorAudioListsbooleanfalseReplace a new playlist with the first loaded playlist,
autoPlayInitLoadPlayListbooleanfalsePlay your new play list right after your new play list is loaded turn false.

Custom operation ui

Support feature:

  • play
  • pause
  • reload
  • change play time
  • change playbackRate
  • change volume
class App extends React.Component{
  constructor() {
    this.audio = null
  }
  render() {
    return (
      <>
        <ReactJkMusicPlayer getAudioInstance={instance => this.audio = instance}/>
        <button onClick={() => this.audio.play()}>play</button>
        <button onClick={() => this.audio.pause()}>pause</button>
        <button onClick={() => this.audio.load()}>reload</button>
        <button onClick={() => (this.audio.currentTime = 40)}>
          change current play time
        </button>
        <button onClick={() => (this.audio.playbackRate = 2)}>
          change play back rate
        </button>
        <button onClick={() => (this.audio.volume = 0.2)}>change volume</button>
      </>
    )
  }
}

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,
  [key: string]: any
}>

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,
  [key: string]: any
}

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, transformedDownloadAudioInfo: TransformedDownloadAudioInfo) => 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> | React.ReactNode | boolean | 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
  getAudioInstance?: (instance: HTMLAudioElement) => void
  autoHiddenCover?: boolean
  onBeforeAudioDownload?: (
    audioInfo: ReactJkMusicPlayerAudioInfo
  ) => Promise<TransformedDownloadAudioInfo>
  clearPriorAudioLists?: boolean
  autoPlayInitLoadPlayList?: boolean
}

export interface TransformedDownloadAudioInfo {
  src: string
  filename?: string
  mimeType?: string
}

License

MIT

Keywords

FAQs

Last updated on 23 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc