GithubHelp home page GithubHelp logo

ruthatd / ima-ad-player Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kslimani/ima-ad-player

0.0 0.0 0.0 1.21 MB

Yet another Google IMA video ad player

License: MIT License

JavaScript 67.52% HTML 32.48%

ima-ad-player's Introduction

MIT license

Google IMA video ad player

Yet another Google IMA HTML5 SDK video ad player.

Getting started

Add the ad player script to your HTML :

<head>
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ima-ad-player@latest/dist/ima-ad-player.min.js"></script>
</head>

Then use the ImaAdPlayer factory to create ad player instance :

ImaAdPlayer({
  video: document.querySelector('.a-video-element'),
  displayContainer: document.querySelector('.a-display-container-element'),
  tag: 'https://myadserver.com/path/to/vast/tag.xml',
}, function(player, error) {
  if (error) {
    // Ad player creation failed
    return console.log(error);
  }

  player.on('ad_begin', function() {
    // Pause content video
  });

  player.on('ad_end', function() {
    // Play or resume content video
  });

  // Must be done as the result of a user action (if autoplay not permitted)
  player.play();
});

The ad player assumes the ad display container and video element are correctly positioned and sized.

Documentation

For a complete example see the HTML development page.

Autoplay

Ad player default behaviour is to assumes that play() method is called when video is allowed to autostart. (ie: autoplay is permitted or called after user interaction)

For that reason, default internal behaviour is to call setAdWillAutoPlay(true) and setAdWillPlayMuted(false) on IMA AdsRequest instance.

It can be changed using adWillAutoPlay and adWillPlayMuted configuration options.

Usage as Node.js external dependency

Add it to your project, for example, using NPM command :

$ npm install ima-ad-player

Then import and use ad player factory :

import ImaAdPlayer from 'ima-ad-player'

ImaAdPlayer({
  // ...
}, function(player, error) {
  // ...
});

About

This library is basically a wrapper on IMA SDK library. The goal is to provide a simple implementation which cover common ad scenarios.

I created this project because I needed to implement the IMA SDK in several other projects without having to duplicate the implementation code.

It is used in the following projects :

License

The MIT License (MIT). Please see License File for more information.

ima-ad-player's People

Contributors

kslimani avatar dependabot[bot] avatar

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.