HTML5 Audio Player
npm install play-audio.jsLightweight Wrapper For HTML5 Audio API
``js
play = require('play-audio.js')
play('song.mp3').autoplay()
`
* Example 1: Playing An Alert Sound
* Example 2: Music player
* Example 3: alert library
`bash`
$ npm install play-audio
`js`
play(['song.mp3', 'song.ogg']).play()
`js`
parent = document.querySelector('.my-player')
play(['song.mp3', 'song.ogg'], parent).autoplay.controls()
If your application isn't structured as a CommonJS package, you can download the distribution file;
`bash`
$ wget https://raw.github.com/azer/play-audio/master/dist/play-audio.js
And include it on your page:
`html`
`js
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']
`
Example:
`js``
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)
* abort
* durationchange
* ended
* error
* pause
* play
* progress
* timeupdate