Lightweight Wrapper For HTML5 Audio API
JavaScript CoffeeScript HTML
Switch branches/tags
Nothing to show
Latest commit e84792c Jan 10, 2017 @azer committed on GitHub Update src.js
Permalink
Failed to load latest commit information.
dist add dist Jul 22, 2013
lib Update src.js Jan 10, 2017
templates better way to pick files by type Jul 22, 2013
.gitignore first commit Jul 21, 2013
.npmignore add dist Jul 22, 2013
Devfile.coffee add dist Jul 22, 2013
README.md Update README.md Sep 22, 2013
global.js add dist Jul 22, 2013
index.js
package.json Update package.json Dec 29, 2016
test.js better way to pick files by type Jul 22, 2013

README.md

play-audio

Lightweight Wrapper For HTML5 Audio API

play = require('play-audio')

play('song.mp3').autoplay()

Install

$ npm install play-audio

Browser Compatibility

play(['song.mp3', 'song.ogg']).play()

Displaying Controls

parent = document.querySelector('.my-player')
play(['song.mp3', 'song.ogg'], parent).autoplay.controls()

How to use without NPM?

If your application isn't structured as a CommonJS package, you can download the distribution file;

$ wget https://raw.github.com/azer/play-audio/master/dist/play-audio.js

And include it on your page:

<script src="play-audio.js"></script>
<script>
  playAudio(['song.mp3', 'song.ogg'])
</script>

Changing Source After Initialization

p = play(['song.mp3', 'song.ogg']).autoplay()
p.src()
// => ['song.mp3', 'song.ogg']

p.src(['new.mp3', 'new.ogg']).play()
p.src()
// => ['new.mp3', 'new.ogg']

API

Example:

play('foo.mp3').volume(0.3).controls().loop().on('ended', function(){
  console.log('End of the song reached')
})

Reference:

  • play(uri, parentElement)
  • .controls
  • .currentTime
  • .element
  • .loop
  • .muted
  • .on(event, function)
  • .pause
  • .play
  • .preload
  • .src(url)
  • .volume(number)

Events

  • abort
  • durationchange
  • ended
  • error
  • pause
  • play
  • progress
  • timeupdate

See complete reference