// During the initialization process
this.videoPlayer.addEventListener('timeupdate', this.handlePlaybackEvents.bind(this));
function handlePlaybackEvents() {
const percent = (this.videoPlayer.currentTime / this.videoPlayer.duration) * 100;
//only fire these beacons during the first loop
if (this.currentLoop === 1 ) {
if (percent >= 0.01 && !this.adStarted.sent) {
// mark sent
this.adStarted.sent = true;
// fire start beacon
const adStartedBeacon = new URL(this.adStarted.beacon);
adStartedBeacon.drop();
// forward event to OMID (related to next section of the document)
if (this.mediaEvents) {
this.mediaEvents.start(this.videoPlayer.duration, this.videoPlayer.muted ? 0 : this.videoPlayer.volume);
}
}
if (percent >= 25 && !this.adFirstQuartile.sent) {
// mark sent
this.adFirstQuartile.sent = true;
// fire firstQuartile beacon
const adFirstQuartileBeacon = new URL(this.adFirstQuartile.beacon);
adFirstQuartileBeacon.drop();
// forward event to OMID (related to next section of the document)
if (this.mediaEvents) {
this.mediaEvents.firstQuartile();
}
}
if (percent >= 50 && !this.adMidpoint.sent) {
// mark sent
this.adMidpoint.sent = true;
// fire midPoint beacon
const adMidpointBeacon = new URL(this.adMidpoint.beacon);
adMidpointBeacon.drop();
// forward event to OMID (related to next section of the document)
if (this.mediaEvents) {
this.mediaEvents.midpoint();
}
}
if (percent >= 75 && !this.adThirdQuartile.sent) {
// mark sent
this.adThirdQuartile.sent = true;
// fire thirdQuartile beacon
const adThirdQuartileBeacon = new URL(this.adThirdQuartile.beacon);
adThirdQuartileBeacon.drop();
// forward event to OMID (related to next section of the document)
if (this.mediaEvents) {
this.mediaEvents.thirdQuartile();
}
}
}