1.1.11 • Published 7 months ago

reaplay v1.1.11

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

React Music Player - Reaplay

React Custom Music Player (with custom HOC component)

the react HOC for create custom players with any styles you like give me your tracks, i will give you the all function and variable you need to create a player

NPM License JavaScript Style Guide

Installation

npm install --save reaplay
yarn add reaplay

Also be sure you have react and react-dom installed in your app

Usage

tsx

import React from 'react';

import { Reaplay, PlayerType } from 'reaplay'

const songList:string[] = [
  "songSrc", // url song
  "songSrc", // url song
   require("./songSrc"), //local song
]

//                         optional ↓
<Reaplay tracks={songList} startIndex={2} >
      {(player: PlayerType) => {
          // player have functions and variables
      }
</Reaplay>

jsx

import React from 'react';

import { Reaplay } from 'reaplay'

const songList = [
  "songSrc", // url song
  "songSrc", // url song
   require("./songSrc"), //local song
]

<Reaplay tracks={songList} >
      {(player) => {
          // player have functions and variables
      }
</Reaplay>

Example

See the example directory for a basic working example of using this project. To run it locally, run npm install in the example directory and then npm start.

or

<Reaplay tracks={songList} >
      {(player) => {
          
          return (
            <>
              <input
                  type='range'
                  value={player.trackProgress}
                  step='1'
                  min='0'
                  max={player.duration ? player.duration : `${player.duration}`}
                  onChange={(e) => player.onScrub(e.target.value)}
                  onMouseUp={(e) => player.onScrubEnd(e)}
                  onKeyUp={(e) => player.onScrubEnd(e)}
                />

                <button onClick={() => player.toPrevTrack()}>prev</button>
                <button onClick={() => player.play()}>Play</button>
                <button onClick={() => player.pause()}>Pause</button>
                <button onClick={() => player.toNextTrack()}>next</button>

                <input
                  type='range'
                  value={player.volume}
                  step='1'
                  min='0'
                  max='100'
                  onChange={(e) => player.setVolume(+e.target.value)}
                />
                <button onClick={() => player.mute()}>mute</button>
                <button onClick={() => player.unmute()}>unmute</button>
            </>
          )
        }
      }
</Reaplay>

Props - HOC Parametrs

ParamTypeDefaultNotes
tracksString Arraynullit's the main param, the required param for "reaplay" working
startIndexNumber0use it for start at custom index of your tracks array
childrenAnyNull---

player props :

Props - properties

PropTypeDefaultNotes
isLoadingBooleanfalseif use Uri tracks, you need wait for the uri will be load
isHaveErrorBooleanfalseif your track returned error, it give you a boolean
trackIndexNumber0the playing index of the tracks array
durationNumbersong durationthe duration of the playing song
durationTextStringsong duration convertedthe duration of the playing song converted to 00:00 string
trackProgressNumberplayed durationthe duration of the played of song
trackStylingstring---the generated style of track progress
isPlayingBooleanfalsethe player on playing or not
isRepeatBooleanfalsethe player on Repeat the song mode or not
volumeNumber100the player volume. 0 to 100
speedNumber1the player playbackRate. 0.5 or 1 or 2
isStopPlayMoreSongBooleanfalseif the song will be end, dont play more anything
isShuffleBooleanfalseif shuffleList will be true, any action do random (next, prev, ended)
isMuteBooleanfalsethe player mute status
bufferedNumber0the buffered value of the song 0 to 100
bufferedTextString0the buffered value of the song 0% to 100%

Props - Events

EventparamDescriptionExample
Logger()the Logger, console.log the properties seconds by seconds for debug or your testingplayer.Logger()
onScrub(value: number)for change track progress on custom durationonChange={(e) => player.onScrub(e.target.value)}
onScrubEnd()optional -- use it on keyUp or ... on your (slider, range, any custom player duration controller)onMouseUp={player.onScrubEnd} onKeyUp={player.onScrubEnd}
setIsPlaying(isPlaying: boolean)for play or pause the song, use it.onClick={() => player.setIsPlaying((isPlay) => !isPlay)}
play()for play the song, use it.onClick={() => player.play()}
pause()for pause the song, use it.onClick={() => player.pause()}
setTrackIndex(trackIndex: number)for change handly playing index.onClick={() => player.setTrackIndex(5)}
toNextTrack()go to next track of the tracks listplayer.toNextTrack()
toPrevTrack()go to prev track of the tracks listplayer.toPrevTrack()
repeat(isRepeat: boolean)turn on or off for repeat the playing songplayer.repeat((isRepeat) => !isRepeat)
setVolume(volume: number)set player volume, 0 to 100player.setVolume(70)
playSlow()set player playbackRate (speed) to 0.5player.playSlow()
playNormal()set player playbackRate (speed) to 1player.playNormal()
playFast()set player playbackRate (speed) to 2player.playFast()
StopPlayMoreSong(stopped: boolean)dont play more anything after the playing song will be endedplayer.StopPlayMoreSong(true)
playRandom()play a random track of your tracks listplayer.playRandom()
playShuffle(shuffle: boolean)the all player action will be random next prev endedplayer.playShuffle((isShuffle) => !isShuffle)
mute()mute the playerplayer.mute()
unmute()unmute the playerplayer.unmute()
forward()forward to 5s laterplayer.forward()
backward()backward to 5s beforeplayer.backward()
forceUpdatePlayer()forece Re-Render playerplayer.forceUpdatePlayer()
update()update playerplayer.update()

Fix Browser Condition :

browsers don't give access to play sound without at least one user interaction with website

License

MIT © amir-alipour - LICENSE

1.1.9

7 months ago

1.1.8

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago

1.1.7

8 months ago

1.1.6

11 months ago

1.1.5

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago