Giter Site home page Giter Site logo

Comments (3)

kslimani avatar kslimani commented on July 23, 2024

Yes, if i remember well, the Clappr "can-autoplay" internal method is exposed in Utils module.

It should be reacheable, for exemple :

Clappr.Utils.canAutoPlayMedia(function(result, error) {
  if (result) {
    // can autoplay
  } else {
    // cannot autoplay
    console.log(error);
  }
});

See also html5 playback wrapper function (which take account of mobile devices).

from clappr-google-ima-html5-preroll.

thekendog avatar thekendog commented on July 23, 2024

Basically I'm running into an issue where ads are being skipped if autoplay isn't enabled in the browser. What's the best route to go in order to autostart the ads only if the browser allows it?

from clappr-google-ima-html5-preroll.

kslimani avatar kslimani commented on July 23, 2024

You could starts with something like this :

<html>
  <head>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr-google-ima-html5-preroll-plugin@latest/dist/clappr-google-ima-html5-preroll-plugin.min.js"></script>
    <style>
      .player {
        width: 640px;
        height: 360px;
        overflow: hidden;
      }
    </style>
  </head>
  <body>
    <div class="player"></div>
    <script>
       (function () {
         var playerElement = document.querySelector('.player');

         var apOpts = {
           timeout: 500,
           inline: false,
           muted: false,
         }

         // Single Inline Linear. See https://developers.google.com/interactive-media-ads/docs/sdks/html5/tags
         var vastTag = 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=';

         Clappr.Utils.canAutoPlayMedia(function(ap, err){
           var player = new Clappr.Player({
             source: 'http://clappr.io/highline.mp4',
             parent: playerElement,
             height: 360,
             width: 640,
             // Set to false and use plugin autostart option (or set to true if tag is false)
             autoPlay: false,
             plugins: {
               core: [ClapprGoogleImaHtml5PrerollPlugin],
             },
             googleImaHtml5PrerollPlugin: {
               tag: vastTag, // VAST tag URL (or false to disable plugin)
               vpaid: 2, // Default is 0 (0 is DISABLED, 1 is ENABLED and 2 is INSECURE)
               autostart: ap,
             }
           });
         }, apOpts);

       })();
    </script>
  </body>
</html>

from clappr-google-ima-html5-preroll.

Related Issues (17)

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.