1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Oinktube/node_modules/can-autoplay
2022-05-20 16:22:54 -03:00
..
build Improving the get restream credentials 2022-05-20 16:22:54 -03:00
lib Improving the get restream credentials 2022-05-20 16:22:54 -03:00
media Moving to node_modules folder to make easier to upgrade 2021-10-26 14:52:45 -03:00
test Improving the get restream credentials 2022-05-20 16:22:54 -03:00
tools Improving the get restream credentials 2022-05-20 16:22:54 -03:00
.babelrc Improving the get restream credentials 2022-05-20 16:22:54 -03:00
CHANGELOG.md Improving the get restream credentials 2022-05-20 16:22:54 -03:00
index.html Improving the get restream credentials 2022-05-20 16:22:54 -03:00
LICENSE Improving the get restream credentials 2022-05-20 16:22:54 -03:00
package.json Improving the get restream credentials 2022-05-20 16:22:54 -03:00
README.md Improving the get restream credentials 2022-05-20 16:22:54 -03:00
rollup.config.js Improving the get restream credentials 2022-05-20 16:22:54 -03:00

can-autoplay.js

The auto-play feature detection in HTMLMediaElement (<audio> or <video>).

FileSize Version

Demo page

Table of contents:

Installation

npm install can-autoplay

Files

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.

API

audio(options)

Parameters:

  • options.inline <Boolean>, check if auto-play is possible for an inline playback, default value is false
  • options.muted <Boolean>, check if auto-play is possible for a muted content
  • options.timeout <Number>, timeout for a check, default value is 250 ms

Returns:

  • <Promise>, resolves to a <Object>:
    • result <Boolean>, true - if auto-play is possible
    • error <Error>, internal or timeout Error object
canAutoplay.audio().then(({result}) => {
  if (result === true) {
    // Can auto-play
  } else {
    // Can not auto-play
  }
})

video(options)

Parameters:

  • options.inline <Boolean>, check if auto-play is possible for an inline playback, default value is false
  • options.muted <Boolean>, check if auto-play is possible for a muted content
  • options.timeout <Number>, timeout for a check, default value is 250 ms

Returns:

  • <Promise>, resoles to a <Object>:
    • result <Boolean>, true - if auto-play is possible
    • error <Error>, internal or timeout Error object
canAutoplay.video().then(({result}) => {
  if (result === true) {
    // Can autoplay
  } else {
    // Can not autoplay
  }
})

Example

import canAutoPlay from 'can-autoplay';

canAutoPlay
    .video({timeout: 100, muted: true})
    .then(({result, error}) => {
        if(result === false){
            console.warn('Error did occur: ', error)
        }
    })

Media

Implementation Details

If it's required to have a legacy browser support you could use latest v2.x.x version of the library.