Giter Site home page Giter Site logo

video-dev / can-autoplay Goto Github PK

View Code? Open in Web Editor NEW
296.0 296.0 29.0 330 KB

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

Home Page: https://video-dev.github.io/can-autoplay/

License: MIT License

HTML 4.80% JavaScript 95.20%
autoplay detection htmlmediaelement

can-autoplay's People

Contributors

arunpbk-stayqrious avatar caiogondim avatar flavioribeiro avatar gkatsev avatar josewhitetower avatar nicolassiver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

can-autoplay's Issues

Autoplay resolving false in Edge 17 with muted check

First of all thank you for having this package available. It makes detecting autoplay way easier than I expected at first. I have successfully implemented this within my project and cross-browser tested it along our supported range (IE11, last 2 Chrome/Safari/Firefox) with a muted video.

And the video snippet is formatted like this plain example (no additional scripting only verifying whether it can play):

<video  autoplay loop muted>
  <source src="http://myfancyvideo.com/video.mp4" type="video/mp4">
</video>

When looking Edge version 15 it gives an expected result true:
image

But when running the following in Edge 17 (v17.17134 to be specific):

canAutoPlay.video({ timeout: 1000, muted: true }).then(({ result }) => {
    console.log(result);
});

It will instantly return false and throws a DOM Exception:

code: 9,
message: "NotSupportedError"

When not checking it autoplay the muted video as expected. So after that I also ran the demo page in Edge and it gives the following results.

image

Feature request : allow to pass html video element in options

Currently, the library creates a video element to perform play using blob source.

It would be nice to be able to pass an already created video element in options object (and create element as default behaviour if no element provided).

The use case if for video player which "recycle" video element to load another media without changing page. (as soon as video is played is the result of user interaction, the video element keep the user consent and can be reused). This technique is used, for example, in Clappr video player.

Safari 11 incorrect detect

canAutoPlay
    .video({timeout: 100, muted: false})
    .then(({result, error}) => {
        
    })

result is always true, but safari 11 doesn't support autoplay with sound

Base64 vs Blob

I hardly see a value in Base64 implementation where Blob implementation works for the majority of library users, and so far nobody discovered real weaknesses of Blob approach.

I propose to do a research and comparison Base64 vs Blob. If we will find out that Blob has only good parts, we should optimize and tune library inner logic around Blob implementation. The idea to have internal regular expressions is not good enough for a small and efficient library.

When I saw a proposal/request for Blob, my instant thoughts were:

  • What is a performance (detection time) difference?
  • How could Blob be done on build step? So we don't need waste time at runtime.
  • What pitfalls with Blob other than overall legacy browser support.

Trying to use this in React project and "Blob" is not defined

Looks like there is a missing dependency "Blob". How do I remedy? I tried installing blob from npm and importing it but it didn't work.

ReferenceError: Blob is not defined
    at eval (webpack-internal:///./packages/interpayments-theme/node_modules/can-autoplay/build/can-autoplay.es.js:6:14)
    at Module../packages/interpayments-theme/node_modules/can-autoplay/build/can-autoplay.es.js (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:5043:1)
    at __webpack_require__ (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:27:30)
    at eval (webpack-internal:///./packages/interpayments-theme/src/components/partials/page-hero.js:10:70)
    at Module../packages/interpayments-theme/src/components/partials/page-hero.js (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:6116:1)
    at __webpack_require__ (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:27:30)
    at eval (webpack-internal:///./packages/interpayments-theme/src/components/home.js:7:77)
    at Module../packages/interpayments-theme/src/components/home.js (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:5900:1)
    at __webpack_require__ (/home/davidrhoderick/Development/interpayments/frontity/build/server.js:27:30)
    at eval (webpack-internal:///./packages/interpayments-theme/src/components/index.js:12:63)

Usage of audio check in muted tab only works first call

Working with version 3.0.2, I have a call to the canAutoplay.audio() which correctly yields false when called the first time. However subsequent calls always return true.

Tried with chrome: Version 108.0.5359.98 (Official Build) (64-bit) on Linux, Chrome on android tablet and the behavior is the same. First call works like it should, second call always returns true.

Push 3.0.0 tag

npm, package.json, and CHANGELOG.md all have v3.0.0, but the git tag doesn't show up - can you git push the tag?

Support for below ES6

Thanks for starting this project!

I tried this out today and had some trouble using uglify as the code is in ES6. Any chance we could add a build step to use babel or something similar to transform the code to ES5?

Bug: The play() request was interrupted by a new load request

Version 3.0.1 give me the following error:

image

In Version 3.0.0 everything is fine.

My Code is the following:

canAutoPlay
          .video({ timeout: 4000, muted: false, inline: true })
          .then((data) => {
            console.log(data);
            const { result } = data;
            const startAutoplay = result === true;
            store.dispatch(actions.init(startAutoplay));
            finishPlayerInitialization(startAutoplay);
          });

Smaller dummy assets

I used a big video asset just as a PoC.
For production use, we should generate an optimized video with audio asset.

Same for audio.

Problem import

Hello, thanks a lot for this project, i have problem, after npm install i imorted can-autoplay like this:
import canAutoPlay from 'can-autoplay';
and browser console show me this:
Uncaught ReferenceError: canAutoplay is not defined
why is it happen?
10x!)

Suppor typescript

Hello! Thanks a lot for you library. I need to get you library in my typescript project, but i didn't find in ts libraries. Do you have plans for publish it? thx

Error: setAttribute("muted","muted") - Not implemented

Error: Not implemented
os: windows 10, windows 7
browsers: Yandex Browser(17.1.0), Opera 54.0.2952, Chrome 67.0.3396
snip:

 .timeout,r=e.inline,a=t(),s=a.element,o=a.source,l=void 0,u=void 0,d=void 0;return s.muted=n,!0===n&&s.setAttribute("muted","muted"),!0===r& 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.