Skip to content

Commit 4db98ff

Browse files
authored
Merge pull request #757 from jorgeucano/master
Feat: add event for play/pause/skip IMA-ADS
2 parents 985c085 + c767504 commit 4db98ff

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ima-ads/vg-ima-ads.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///<reference path='./google.ima.ts'/>
2-
import { Component, ElementRef, Input, HostBinding, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
2+
import { Component, ElementRef, Input, HostBinding, ViewEncapsulation, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
33
import { IPlayable } from '../core/vg-media/i-playable';
44
import { VgAPI } from '../core/services/vg-api';
55
import { VgEvents } from '../core/events/vg-events';
@@ -34,6 +34,10 @@ export class VgImaAds implements OnInit, OnDestroy {
3434
@Input() vgAdTagUrl: string;
3535
@Input() vgSkipButton: string;
3636

37+
@Output() onAdStart: EventEmitter<boolean> = new EventEmitter();
38+
@Output() onAdStop: EventEmitter<boolean> = new EventEmitter();
39+
@Output() onSkipAd: EventEmitter<boolean> = new EventEmitter();
40+
3741
elem: HTMLElement;
3842
target: IPlayable;
3943
ima: Ima;
@@ -225,15 +229,18 @@ export class VgImaAds implements OnInit, OnDestroy {
225229

226230
onClickSkip() {
227231
this.ima.adsManager.skip();
232+
this.onSkipAd.emit(true);
228233
}
229234

230235
onContentPauseRequested() {
231236
this.show();
232237
this.API.pause();
238+
this.onAdStop.emit(true);
233239
}
234240

235241
onContentResumeRequested() {
236242
this.API.play();
243+
this.onAdStart.emit(true);
237244
this.hide();
238245
}
239246

@@ -243,19 +250,22 @@ export class VgImaAds implements OnInit, OnDestroy {
243250
}
244251
this.hide();
245252
this.API.play();
253+
this.onAdStop.emit(true);
246254
}
247255

248256
onAllAdsComplete() {
249257
this.hide();
250258
// The last ad was a post-roll
251259
if (this.ima.adsManager.getCuePoints().join().indexOf('-1') >= 0) {
252260
this.API.pause(); // it was stop() in Videogular v1
261+
this.onAdStop.emit(true);
253262
}
254263
}
255264

256265
onAdComplete() {
257266
// TODO: Update view with current ad count
258267
this.ima.currentAd++;
268+
this.onAdStop.emit(true);
259269
}
260270

261271
show() {
@@ -270,6 +280,7 @@ export class VgImaAds implements OnInit, OnDestroy {
270280

271281
onContentEnded() {
272282
this.ima.adsLoader.contentComplete();
283+
this.onAdStop.emit(true);
273284
}
274285

275286
onChangeFullscreen(fsState: boolean) {

0 commit comments

Comments
 (0)