a bare-bones <audio> and <video> abstraction
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.npmignore
LICENSE.md
README.md
index.js
package.json
test.js

README.md

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:

  • 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)

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

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

License

MIT, see LICENSE.md for details.