googleads / videojs-ima

IMA SDK Plugin for Video.js
Apache License 2.0
450 stars 284 forks source link

Replay button after ad [support] #935

Closed damjan25 closed 4 years ago

damjan25 commented 4 years ago

Is it possible to show replay button after ad? I tried pausing the player (this.player.ima.getAdsManager().pause(); and pauseAds()) on events ENDED and COMPLETE but I was not able to prevent player from closing/disposing after. Is there a different aproach on how to do this properly ?

What I want to do: -I just want to have a replay button after video ad is done playing -On button "replay" click I want to just restart the video ad without triggering new AD IMPRESSION

I managed to pause it by pausing (this.player.ima.getAdsManager().pause(); pauseAds()) the player on ENDED event and with use of debugger break point(setting break point and then after few seconds clicking resume script) inside COMPLETE event listener, but as soon as I remove break point and run it without it, it does not work anymore

If there is no specific property that ads replay button, I might just do something like this and show replay icon I guess:

videoEl.addEventListener("timeupdate", function () {
    if (videoEl.currentTime > videoEl.duration - 0.5) {
        videoEl.pause();
    }
});

But then there is a problem that currentTime does not work on android chrome :(

Ok I found a way to get correct currentTime on android chrome as well:

player.ima.addEventListener(EventType.AD_PROGRESS, (IMAEvent) => {
        let adProgressData= IMAEvent.getAdData();
        console.log(parseInt(adProgressData.duration)-parseInt(adProgressData.currentTime));
      });
damjan25 commented 4 years ago

@Kiro705 Is there a way to set currentTime through ima ? Since setting current time on html5 video element doesn't do anything(since its always 0 or 0.04). document.querySelector("video").currentTime = 0;

Would it be possible to set it through this object ? https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdProgressData#currentTime

Kiro705 commented 4 years ago

Hello @damjan25 ,

Unfortunately IMA does not support a method to set the current time, adEvent.current time is the time when the event was fired, and changing the value will not seek to that place within the ad.

In addition, I do not believe there is a supported way to replay viewed ads.

damjan25 commented 4 years ago

Thank you for answer and support :)