1.0.2 • Published 4 years ago

use-html-audio v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

use-html-audio

A react custom hook for html audio player purpose with queue support.

Install

using npm:

$ npm install use-html-audio

using yarn:

$ yarn add use-html-audio

Usage

import { useHtmlAudio } from "use-html-audio";

const MyComponent = () => {
  const player = useHtmlAudio(hookInputs);

  // player.element should be included somewhere in the jsx
  // it wont affect the UI in any way (it is a hidden <audio> element).
  return <div>{player.element}</div>;
};

hookInputs

nametypedesc
queue*{src:"" , id: "" }an array of audio urls with a unique id
autoNextbooleanautomatically play next track on finish
autoPlaybooleanautomatically play the first track
autoLoadbooleanautomatically load the first track

player

nametypedesc
elementhtml elementan tag that should be put in the jsx
loadingboolean
durationnumber (sec)full length of the current track
currentDurationnumber(sec)current duration
progressnumber
playingboolean
currentTrackobject
isMutedboolean
currentIndexnumber
bufferingboolean
audioEndedboolean
togglePlayfuntion
seekBySecfuntionseekByPercent(sec)
seekByPercentfuntionseekByPercent(percent), percent = 0-1
playNextfunction
playPrevfuntion
playAtIndexfuntion
playAtIdfuntion
toggleMutefuntion