react-controller-audio-player
This is a HTML5 audio player react component. It uses a render prop which gives you maximum flexibility with a minimal API because you are responsible for the rendering of everything and you simply apply props to what you're rendering.
Install:
npm install react-controller-audio-player --save
Usage
import React Fragment from 'react';import ReactDOM from 'react-dom';import Player from 'react-controller-audio-player';// sample styleimport from 'react-controller-audio-player/dist/style.css'; const sampleClassNames = container: 'container' timeLine: 'timeLine' playHead: 'playHead' timeLabel: 'timeLabel'; const Play = <svg ='50px' ='1.1' ='0 0 20 20' ='50px'> <g ='none' ='evenodd' ='none' ='1'> <g ='#E98074' ='translate(-126.000000, -85.000000)'> <g ='translate(126.000000, 85.000000)'> <path ='M10,0 C4.5,0 0,4.5 0,10 C0,15.5 4.5,20 10,20 C15.5,20 20,15.5 20,10 C20,4.5 15.5,0 10,0 L10,0 Z M8,14.5 L8,5.5 L14,10 L8,14.5 L8,14.5 Z' /> </g> </g> </g> </svg>; const Pause = <svg ='50px' ='1.1' ='0 0 20 20' ='50px'> <g ='none' ='evenodd' ='none' ='1'> <g ='#E98074' ='translate(0.000000, -85.000000)'> <g ='translate(0.000000, 85.000000)'> <path ='M10,0 C4.5,0 0,4.5 0,10 C0,15.5 4.5,20 10,20 C15.5,20 20,15.5 20,10 C20,4.5 15.5,0 10,0 L10,0 Z M9,14 L7,14 L7,6 L9,6 L9,14 L9,14 Z M13,14 L11,14 L11,6 L13,6 L13,14 L13,14 Z' /> </g> </g> </g> </svg>; // Dummy time formatter { if Number return 'Not a valid number'; const pad = input < 10 ? `0` : ``; const time = ; const hours = Math; const minutes = Math % 60; const seconds = Math; return `::`;} const src = 'some audio source'; const App = <Player => canPlay playing pause play movePlayHead playHeadMarginLeft setOnPlayHead onPlayHead duration timeLineRef playHeadRef playedTime <Fragment> canPlay ? <div => <div => playing ? <Pause /> : <Play /> </div> <span =></span> <div = = = = = = > <div = = = /> </div> <span =></span> </div> : <span>Unable to play audio</span> </Fragment> </Player>; ReactDOM;
Component Inspired by
Contributions of any kind welcome!
LICENSE
MIT