dg-play-audio
HTML5 Audio Player
Last updated 4 years ago by dguttman .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dg-play-audio 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.0.4                                ...           latest (4 years ago)

2 Versions

  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |