The auto-play feature detection in HTMLMediaElement (`<audio>` or `<video>`).
npm install can-autoplayThe auto-play feature detection in HTMLMediaElement ( or ).
Table of contents:
- Installation
- Files
- API
- audio(options)
- video(options)
- Example
- Media
- Implementation Details
```
npm install can-autoplay
Build files are available in the build/ directory. Bundlers will choose get the correct file chosen for them but if you just want to include it on the page, grab the build/can-autoplay.js file.
Parameters:
- options.inline , check if auto-play is possible for an inline playback, default value is false
- options.muted , check if auto-play is possible for a muted content
- options.timeout , timeout for a check, default value is 250 ms
Returns:
- , resolves to a
`js`
canAutoplay.audio().then(({result}) => {
if (result === true) {
// Can auto-play
} else {
// Can not auto-play
}
})
Parameters:
- options.inline , check if auto-play is possible for an inline playback, default value is false
- options.muted , check if auto-play is possible for a muted content
- options.timeout , timeout for a check, default value is 250 ms
Returns:
- , resoles to a
`js`
canAutoplay.video().then(({result}) => {
if (result === true) {
// Can autoplay
} else {
// Can not autoplay
}
})
`js
import canAutoPlay from 'can-autoplay';
canAutoPlay
.video({timeout: 100, muted: true})
.then(({result, error}) => {
if(result === false){
console.warn('Error did occur: ', error)
}
})
`
- audio.mp3. Created by Weston Ruter (@westonruter). Smallest possible (<0.000001 seconds long) audio file.video.mp4
- . Source: https://github.com/mathiasbynens/small
If it's required to have a legacy browser support you could use latest v2.x.x` version of the library.