MediaPlayer
A smart media player for React, for audio and video content.
View demo site
THIS IS THE v1.x DOCUMENTATION - v2.x IS COMING SOON
Installation
npm i -D @rs1/media-player
Usage
You can use the component inside your React app by following these steps.
Import it in your app:
import Player from '@rs1/media-player'
define the media you want to play:
const media = {
title: 'Big Buck Bunny',
artist: 'Blender Foundation',
src: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
poster: 'https://en.wikipedia.org/wiki/Big_Buck_Bunny#/media/File:Big_buck_bunny_poster_big.jpg',
video: true,
}
then use it as a component with the prop media
:
<Player media={media} />
enjoy your new amazing media player!
Configuration options
There are dozens of settings you can tune based on your needs.
General options
<Player
media={media}
config={{
options: {
isPlaylist: true,
loop: false,
canMute: true,
canFullScreen: true,
autoHideControls: 5,
metadataOnMedia: true,
playerSize: [0, 0],
autoResize: true,
autoPlay: true,
},
}}
/>
Styling options
<Player
media={media}
config={{
style: {
controlsColor: '#ffffff',
metadataOnMediaColor: '#ffffff',
accentColor: '#009fe3',
loaderColor: '#ffffff',
errorColor: '#ed4337',
fontFamily: 'Verdana',
mediaBackground: '#000000',
},
}}
/>
Icons options
<Player
media={media}
config={{
icons: {
error: faExclamationCircle,
loading: faSpinner,
seeking: faSpinner,
unmuted: faVolumeMute,
muted: faVolumeUp,
fullscreen: faCompressArrowsAlt,
exit_fullscreen: faExpandArrowsAlt,
play: faPlayCircle,
pause: faPauseCircle,
previous: faBackward,
backward10: makeIcon('10backward', backward10svg, [512, 512]),
next: faForward,
forward10: makeIcon('10forward', forward10svg, [512, 512]),
},
}}
/>
Build custom icons:
import { makeIcon } from '@rs1/media-player'
import svgFile from 'path/to/file.svg'
const customIcon = makeIcon(
'my-icon',
svgFile,
[512, 512],
)
export default customIcon
Callback options
<Player
media={media}
config={{
actions: {
onError: () => console.log(`An error occurred`),
onPrevious: () => console.log(`Previous track requested`),
onNext: () => console.log(`Next track requested`),
onPlayingChanged: playing => console.log(`The media is ${playing ? 'playing' : 'paused'}`),
onLoadingChanged: loading => console.log(`The media is ${loading ? 'loading' : 'loaded'}`),
onSeekingChanged: seeking => console.log(`The media is ${seeking ? 'seeking' : 'seeked'}`),
onBufferChanged: buffer => console.log(`The download progress is at ${Math.round(buffer * 100)}%`),
onTimeChanged: time => console.log(`The media is at ${Math.round(time)}sec`),
onDurationChanged: duration => console.log(`The media has a duration of ${duration}sec`),
onMuteChanged: muted => console.log(`The media is now ${muted ? 'muted' : 'unmuted'}`),
onFullScreenChanged: fullscreen => console.log(`The media is now ${fullscreen ? '' : 'not '}full screen`),
onStateChanged: state => console.log(`The media player state is now: ${JSON.stringify(state)}`),
},
}}
/>