Skip to content

Commit

Permalink
Merge pull request #757 from jorgeucano/master
Browse files Browse the repository at this point in the history
Feat: add event for play/pause/skip IMA-ADS
  • Loading branch information
Elecash authored Jul 16, 2018
2 parents 985c085 + c767504 commit 4db98ff
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ima-ads/vg-ima-ads.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///<reference path='./google.ima.ts'/>
import { Component, ElementRef, Input, HostBinding, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
import { Component, ElementRef, Input, HostBinding, ViewEncapsulation, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { IPlayable } from '../core/vg-media/i-playable';
import { VgAPI } from '../core/services/vg-api';
import { VgEvents } from '../core/events/vg-events';
Expand Down Expand Up @@ -34,6 +34,10 @@ export class VgImaAds implements OnInit, OnDestroy {
@Input() vgAdTagUrl: string;
@Input() vgSkipButton: string;

@Output() onAdStart: EventEmitter<boolean> = new EventEmitter();
@Output() onAdStop: EventEmitter<boolean> = new EventEmitter();
@Output() onSkipAd: EventEmitter<boolean> = new EventEmitter();

elem: HTMLElement;
target: IPlayable;
ima: Ima;
Expand Down Expand Up @@ -225,15 +229,18 @@ export class VgImaAds implements OnInit, OnDestroy {

onClickSkip() {
this.ima.adsManager.skip();
this.onSkipAd.emit(true);
}

onContentPauseRequested() {
this.show();
this.API.pause();
this.onAdStop.emit(true);
}

onContentResumeRequested() {
this.API.play();
this.onAdStart.emit(true);
this.hide();
}

Expand All @@ -243,19 +250,22 @@ export class VgImaAds implements OnInit, OnDestroy {
}
this.hide();
this.API.play();
this.onAdStop.emit(true);
}

onAllAdsComplete() {
this.hide();
// The last ad was a post-roll
if (this.ima.adsManager.getCuePoints().join().indexOf('-1') >= 0) {
this.API.pause(); // it was stop() in Videogular v1
this.onAdStop.emit(true);
}
}

onAdComplete() {
// TODO: Update view with current ad count
this.ima.currentAd++;
this.onAdStop.emit(true);
}

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

onContentEnded() {
this.ima.adsLoader.contentComplete();
this.onAdStop.emit(true);
}

onChangeFullscreen(fsState: boolean) {
Expand Down

0 comments on commit 4db98ff

Please sign in to comment.