Home

Awesome

simple-media-element

experimental

A bare-bones <audio> and <video> element abstraction. Handles mime-type lookups for common extensions and allows setting attributes via an options object.

Install

npm i simple-media-element --save

Example

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'
])

Usage

NPM

element = media.video([src], [opt])

Creates a new <video> element with src, a source or array of sources. A source can be:

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.

element = media.audio([src], [opt])

The same as above, but returns a <audio> element instead.

License

MIT, see LICENSE.md for details.