A bare-bones <audio>
and <video>
element abstraction. Handles mime-type lookups for common extensions and allows setting attributes via an options object.
npm i simple-media-element --save
const media = require('simple-media-element')
// create a new <audio> tag
const audioElement = media.audio('assets/foo.mp3', {
loop: true,
crossOrigin: 'Anonymous',
volume: 0.5
})
// play the audio
audioElement.play()
// create a new <video> tag with multiple sources
const videoElement = media.video([
'assets/video.ogv',
'assets/video.webm'
])
Creates a new <video>
element with src
, a source or array of sources. A source can be:
- A string; in which case the mime-type is guessed from extension
- A object with
{ src, type }
- A
<source>
element
These are added as children to the media element.
The options given to opt
. If any is unspecified, it will not be set on the element.
loop
(Boolean)muted
(Boolean)autoplay
(Boolean)controls
(Boolean)crossOrigin
(String)preload
(String)poster
(String)volume
(Number)
The same as above, but returns a <audio>
element instead.
MIT, see LICENSE.md for details.