diff --git a/README.md b/README.md index 5d89453f..268dc55d 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,27 @@ the previous snippet. A summary of all settings follows:
(5) [google.ima.ImaSdkSettings.VpaidMode](//developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.ImaSdkSettings.VpaidMode) +## IMA Plugin Ad Events +The IMA Plugin will fire events that can be listened for. Ad lifecycle events can be listened for by following our [Advanced Example](https://github.com/googleads/videojs-ima/blob/master/examples/advanced/ads.js). Other events are emited from the videojs player. Please see the below example to set up listeners for these events. + +```javascript +this.player = videojs('content_video'); + +this.player.on('ads-manager', function(response){ + var adsManager = response.adsManager; + // Your code in response to the `ads-manager` event. +}) +``` + +Below are the events added by the videojs-ima plugin to the videojs player. + +| Event | Event String | Payload | +|-------|--------------|---------| +| Ad Started | 'ads-ad-started' | none | +| Ads Manager | 'ads-manager' | [google.ima.AdsManager](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsManager) | +| Ads Loader | 'ads-loader' | [google.ima.AdsLoader](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsLoader) | +| Ads Request | 'ads-request' | [google.ima.AdsRequest](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsRequest) | + ## Disable automatic ad break playback In some circumstances you may want to prevent the SDK from playing ad breaks until you're ready for them. In this scenario, you can disable automatic diff --git a/src/sdk-impl.js b/src/sdk-impl.js index 0438ebab..3bc5f7d8 100644 --- a/src/sdk-impl.js +++ b/src/sdk-impl.js @@ -183,6 +183,11 @@ SdkImpl.prototype.initAdObjects = function() { google.ima.AdErrorEvent.Type.AD_ERROR, this.onAdsLoaderError.bind(this), false); + + this.controller.playerWrapper.vjsPlayer.trigger({ + type: 'ads-loader', + adsLoader: this.adsLoader, + }); }; /** @@ -224,7 +229,10 @@ SdkImpl.prototype.requestAds = function() { } this.adsLoader.requestAds(adsRequest); - this.controller.triggerPlayerEvent('ads-request', adsRequest); + this.controller.playerWrapper.vjsPlayer.trigger({ + type: 'ads-request', + AdsRequest: adsRequest, + }); }; @@ -284,6 +292,11 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) { this.onAdResumed.bind(this)); } + this.controller.playerWrapper.vjsPlayer.trigger({ + type: 'ads-manager', + adsManager: this.adsManager, + }); + if (!this.autoPlayAdBreaks) { this.initAdsManager(); }