1.2.0 • Published 5 years ago
@firstandthird/can-autoplay v1.2.0
can-autoplay.js
The auto-play feature detection in HTMLMediaElement (<audio> or <video>).
Table of contents:
Installation
npm install can-autoplayFiles
Build files are available in the dist/ directory. Bundlers will choose get the correct file chosen for them but if you just want to include it on the page, grab the dist/can-autoplay.js file.
API
audio(options)
Parameters:
- options.inline
<Boolean>, check if auto-play is possible for an inline playback, default value isfalse - options.muted
<Boolean>, check if auto-play is possible for a muted content - options.timeout
<Number>, timeout for a check, default value is250ms
Returns:
<Promise>, resoles to a<Object>:result <Boolean>,true- if auto-play is possibleerror <Error>, internal or timeout Error object
canAutoplay().then(({result}) => {
if (result === true) {
// Can auto-play
} else {
// Can not auto-play
}
})Media
video.mp4. Source: https://github.com/mathiasbynens/small