From 80813e0d77b6799943c4f33b6c88e2d8f1f5855f Mon Sep 17 00:00:00 2001 From: saravanan Date: Wed, 20 Mar 2024 18:58:56 +0800 Subject: [PATCH 01/10] enabled support to display the remaining time in the ad break --- src/ts/stringutils.ts | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index a1a6782d6..e653eddfa 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -1,4 +1,4 @@ -import { PlayerAPI } from 'bitmovin-player'; +import { LinearAd, PlayerAPI } from 'bitmovin-player'; import { i18n } from './localization/i18n'; export namespace StringUtils { @@ -96,7 +96,7 @@ export namespace StringUtils { */ export function replaceAdMessagePlaceholders(adMessage: string, skipOffset: number, player: PlayerAPI) { let adMessagePlaceholderRegex = new RegExp( - '\\{(remainingTime|playedTime|adDuration)(}|%((0[1-9]\\d*(\\.\\d+(d|f)|d|f)|\\.\\d+f|d|f)|hh:mm:ss|mm:ss)})', + '\\{(remainingTime|playedTime|adDuration|adBreakRemainingTime)(}|%((0[1-9]\\d*(\\.\\d+(d|f)|d|f)|\\.\\d+f|d|f)|hh:mm:ss|mm:ss)})', 'g', ); @@ -112,7 +112,35 @@ export namespace StringUtils { time = player.getCurrentTime(); } else if (formatString.indexOf('adDuration') > -1) { time = player.getDuration(); + } else if (formatString.indexOf('adBreakRemainingTime') > -1) { // To display the remaining time in the ad bread as opposed to in the ad + time = 0; + + if (player.ads.isLinearAdActive()) { + let scheduledAds = player.ads.getActiveAdBreak().ads; + let durations: number[] = []; + let activeAd = player.ads.getActiveAd(); + let indexOfActiveAd: number = 0; + let totaldurationOfAdsPlayed: number = 0; + + for(let i=0; i time + current, 0); + + // Compute duration of ads in adreak already played + totaldurationOfAdsPlayed = durations.slice(0, indexOfActiveAd).reduce((totaldurationOfAdsPlayed, current) => totaldurationOfAdsPlayed + current, 0); + time = time - player.getCurrentTime() - totaldurationOfAdsPlayed; + } } + return formatNumber(Math.round(time), formatString); }); } From 8163ee247fa0794878bd602c6548c74d888cef70 Mon Sep 17 00:00:00 2001 From: saravanan Date: Wed, 20 Mar 2024 20:03:58 +0800 Subject: [PATCH 02/10] removed redundant code --- src/ts/stringutils.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index e653eddfa..3bbf2e110 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -120,7 +120,6 @@ export namespace StringUtils { let durations: number[] = []; let activeAd = player.ads.getActiveAd(); let indexOfActiveAd: number = 0; - let totaldurationOfAdsPlayed: number = 0; for(let i=0; i time + current, 0); + // Compute duration of ads to be played (incl active ad) + time = durations.slice(indexOfActiveAd).reduce((time, current) => time + current, 0); - // Compute duration of ads in adreak already played - totaldurationOfAdsPlayed = durations.slice(0, indexOfActiveAd).reduce((totaldurationOfAdsPlayed, current) => totaldurationOfAdsPlayed + current, 0); - time = time - player.getCurrentTime() - totaldurationOfAdsPlayed; + // And minus time played + time = time - player.getCurrentTime(); } } From 071ee13ba9ac7160cb61c3ef31fb1d56e2a3f268 Mon Sep 17 00:00:00 2001 From: saravanan Date: Tue, 16 Apr 2024 12:09:11 +0800 Subject: [PATCH 03/10] fixed erratic countdown behaviour --- src/ts/stringutils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index 3bbf2e110..3e77e4ce9 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -1,4 +1,4 @@ -import { LinearAd, PlayerAPI } from 'bitmovin-player'; +import { LinearAd, PlayerAPI, TimeMode } from 'bitmovin-player'; import { i18n } from './localization/i18n'; export namespace StringUtils { @@ -115,6 +115,7 @@ export namespace StringUtils { } else if (formatString.indexOf('adBreakRemainingTime') > -1) { // To display the remaining time in the ad bread as opposed to in the ad time = 0; + // compute list of ads and index of active ad if (player.ads.isLinearAdActive()) { let scheduledAds = player.ads.getActiveAdBreak().ads; let durations: number[] = []; @@ -132,10 +133,13 @@ export namespace StringUtils { } } // Compute duration of ads to be played (incl active ad) - time = durations.slice(indexOfActiveAd).reduce((time, current) => time + current, 0); - + let duration = durations.slice(indexOfActiveAd).reduce((prev, current) => prev + current, 0); + + // time played + let currentTime = player.getCurrentTime(); + // And minus time played - time = time - player.getCurrentTime(); + time = duration - currentTime; } } From c0025a441669f4056f06aa07125b5deeae82e284 Mon Sep 17 00:00:00 2001 From: saravanan Date: Mon, 12 Aug 2024 14:04:16 +0800 Subject: [PATCH 04/10] updated function documentation and code per code review --- src/ts/stringutils.ts | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index 3e77e4ce9..6920f7104 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -1,4 +1,4 @@ -import { LinearAd, PlayerAPI, TimeMode } from 'bitmovin-player'; +import { Ad, LinearAd, PlayerAPI, TimeMode } from 'bitmovin-player'; import { i18n } from './localization/i18n'; export namespace StringUtils { @@ -70,8 +70,8 @@ export namespace StringUtils { /** * Fills out placeholders in an ad message. * - * Has the placeholders '{remainingTime[formatString]}', '{playedTime[formatString]}' and - * '{adDuration[formatString]}', which are replaced by the remaining time until the ad can be skipped, the current + * Has the placeholders '{remainingTime[formatString]}', '{playedTime[formatString]}', + * '{adDuration[formatString]}' and {adBreakRemainingTime[formatString]}, which are replaced by the remaining time until the ad can be skipped, the current * time or the ad duration. The format string is optional. If not specified, the placeholder is replaced by the time * in seconds. If specified, it must be of the following format: * - %d - Inserts the time as an integer. @@ -88,6 +88,8 @@ export namespace StringUtils { * An input value of 100 would be displayed as: 'Ad: 01:40 secs' * - { text: 'Ad: {remainingTime%f} secs' } * An input value of 100 would be displayed as: 'Ad: 100.0 secs' + * - { text: 'Adbreak: {adBreakRemainingTime%f} secs' } + * Adbreak with 2 ads each 50 seconds would be displayed as: 'Adbreak: 100.0 secs' * * @param adMessage an ad message with optional placeholders to fill * @param skipOffset if specified, {remainingTime} will be filled with the remaining time until the ad can be skipped @@ -115,25 +117,19 @@ export namespace StringUtils { } else if (formatString.indexOf('adBreakRemainingTime') > -1) { // To display the remaining time in the ad bread as opposed to in the ad time = 0; - // compute list of ads and index of active ad + // compute list of ads and calculate duration of remaining ads based on index of active ad if (player.ads.isLinearAdActive()) { - let scheduledAds = player.ads.getActiveAdBreak().ads; - let durations: number[] = []; - let activeAd = player.ads.getActiveAd(); - let indexOfActiveAd: number = 0; - - for(let i=0; i player.ads.getActiveAd().id == ad.id; + const indexOfActiveAd = player.ads.getActiveAdBreak().ads.findIndex(isActiveAd) + const duration = player.ads.getActiveAdBreak().ads.slice(indexOfActiveAd) + .map(ad => { + if(ad.isLinear) { + return (ad as LinearAd).duration + } else { + return 0 } - } - } - // Compute duration of ads to be played (incl active ad) - let duration = durations.slice(indexOfActiveAd).reduce((prev, current) => prev + current, 0); + }) + .reduce((prev, current) => prev + current, 0); // time played let currentTime = player.getCurrentTime(); From 6aac84a6d6776917b870ddecfd9f525822d30a20 Mon Sep 17 00:00:00 2001 From: saravanan Date: Mon, 12 Aug 2024 14:12:31 +0800 Subject: [PATCH 05/10] removed unused import --- src/ts/stringutils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index 6920f7104..d2ed34dfe 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -1,4 +1,4 @@ -import { Ad, LinearAd, PlayerAPI, TimeMode } from 'bitmovin-player'; +import { Ad, LinearAd, PlayerAPI } from 'bitmovin-player'; import { i18n } from './localization/i18n'; export namespace StringUtils { @@ -89,7 +89,7 @@ export namespace StringUtils { * - { text: 'Ad: {remainingTime%f} secs' } * An input value of 100 would be displayed as: 'Ad: 100.0 secs' * - { text: 'Adbreak: {adBreakRemainingTime%f} secs' } - * Adbreak with 2 ads each 50 seconds would be displayed as: 'Adbreak: 100.0 secs' + * Adbreak with 2 ads each 50 seconds would be displayed as: 'Ad: 100.0 secs' * * @param adMessage an ad message with optional placeholders to fill * @param skipOffset if specified, {remainingTime} will be filled with the remaining time until the ad can be skipped From 73cd981c83bda9349d0518b6271ca572935ee8b4 Mon Sep 17 00:00:00 2001 From: saravanan Date: Mon, 12 Aug 2024 14:18:35 +0800 Subject: [PATCH 06/10] simplified code --- src/ts/stringutils.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index d2ed34dfe..3e3095a92 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -131,11 +131,8 @@ export namespace StringUtils { }) .reduce((prev, current) => prev + current, 0); - // time played - let currentTime = player.getCurrentTime(); - - // And minus time played - time = duration - currentTime; + // And remaning ads duration minus time played + time = duration - player.getCurrentTime(); } } From 71d164484c905406dd5bf7ee4a469bf06f3e4556 Mon Sep 17 00:00:00 2001 From: saravanan Date: Wed, 21 Aug 2024 11:15:33 +0800 Subject: [PATCH 07/10] fixed nits and linting issues --- src/ts/stringutils.ts | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/ts/stringutils.ts b/src/ts/stringutils.ts index da9f771b5..f54c1326d 100644 --- a/src/ts/stringutils.ts +++ b/src/ts/stringutils.ts @@ -73,7 +73,7 @@ export namespace StringUtils { /** * Fills out placeholders in an ad message. * - * Has the placeholders '{remainingTime[formatString]}', '{playedTime[formatString]}', + * Has the placeholders '{remainingTime[formatString]}', '{playedTime[formatString]}', * '{adDuration[formatString]}' and {adBreakRemainingTime[formatString]}, which are replaced by the remaining time until the ad can be skipped, the current * time or the ad duration. The format string is optional. If not specified, the placeholder is replaced by the time * in seconds. If specified, it must be of the following format: @@ -92,7 +92,7 @@ export namespace StringUtils { * - { text: 'Ad: {remainingTime%f} secs' } * An input value of 100 would be displayed as: 'Ad: 100.0 secs' * - { text: 'Adbreak: {adBreakRemainingTime%f} secs' } - * Adbreak with 2 ads each 50 seconds would be displayed as: 'Ad: 100.0 secs' + * Adbreak with 2 ads each 50 seconds would be displayed as: 'Ad: 100.0 secs' * * @param adMessage an ad message with optional placeholders to fill * @param skipOffset if specified, {remainingTime} will be filled with the remaining time until the ad can be skipped @@ -117,28 +117,22 @@ export namespace StringUtils { time = player.getCurrentTime(); } else if (formatString.indexOf('adDuration') > -1) { time = player.getDuration(); - } else if (formatString.indexOf('adBreakRemainingTime') > -1) { // To display the remaining time in the ad bread as opposed to in the ad + } else if (formatString.indexOf('adBreakRemainingTime') > -1) { // To display the remaining time in the ad break as opposed to in the ad time = 0; - + // compute list of ads and calculate duration of remaining ads based on index of active ad if (player.ads.isLinearAdActive()) { - const isActiveAd = (ad : Ad) => player.ads.getActiveAd().id == ad.id; - const indexOfActiveAd = player.ads.getActiveAdBreak().ads.findIndex(isActiveAd) - const duration = player.ads.getActiveAdBreak().ads.slice(indexOfActiveAd) - .map(ad => { - if(ad.isLinear) { - return (ad as LinearAd).duration - } else { - return 0 - } - }) - .reduce((prev, current) => prev + current, 0); - + const isActiveAd = (ad: Ad) => player.ads.getActiveAd().id === ad.id; + const indexOfActiveAd = player.ads.getActiveAdBreak().ads.findIndex(isActiveAd); + const duration = player.ads.getActiveAdBreak().ads + .slice(indexOfActiveAd) + .reduce((total, ad) => total + (ad.isLinear ? (ad as LinearAd).duration : 0), 0); + // And remaning ads duration minus time played time = duration - player.getCurrentTime(); } } - + return formatNumber(Math.round(time), formatString); }); } From f38cb39fe272ab6d718019d5fe431fc910a36d3c Mon Sep 17 00:00:00 2001 From: saravanan Date: Wed, 21 Aug 2024 11:32:18 +0800 Subject: [PATCH 08/10] added changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55db7cd03..958fc6821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.70.0] - 2024-08-21 +### Added +- Support for a new adMessagePlaceholder `adBreakRemainingTime` in [AdMessageLabel](https://cdn.bitmovin.com/player/ui/3/docs/classes/AdMessageLabel.html). It displays the remaining time in an ad break. [Documentation](https://cdn.bitmovin.com/player/ui/3/docs/functions/StringUtils.replaceAdMessagePlaceholders.html) on usage. + ## [3.69.0] - 2024-08-14 ### Added - API doc generation and publishing. The API doc from the UI can be found [here](https://cdn.bitmovin.com/player/ui/3/docs/index.html) From 39ab4a22a54633aec7c629d879094ff847be7af0 Mon Sep 17 00:00:00 2001 From: saravanans-github Date: Wed, 21 Aug 2024 14:48:42 +0800 Subject: [PATCH 09/10] Update CHANGELOG.md Co-authored-by: Felix Hochgruber --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 958fc6821..bfd0e3fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [3.70.0] - 2024-08-21 +## [Unreleased] ### Added - Support for a new adMessagePlaceholder `adBreakRemainingTime` in [AdMessageLabel](https://cdn.bitmovin.com/player/ui/3/docs/classes/AdMessageLabel.html). It displays the remaining time in an ad break. [Documentation](https://cdn.bitmovin.com/player/ui/3/docs/functions/StringUtils.replaceAdMessagePlaceholders.html) on usage. From 2a5bece3fd062d6239056597033dec0def504e33 Mon Sep 17 00:00:00 2001 From: saravanans-github Date: Wed, 21 Aug 2024 14:48:59 +0800 Subject: [PATCH 10/10] Update CHANGELOG.md Co-authored-by: Felix Hochgruber --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd0e3fc0..fee643bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added -- Support for a new adMessagePlaceholder `adBreakRemainingTime` in [AdMessageLabel](https://cdn.bitmovin.com/player/ui/3/docs/classes/AdMessageLabel.html). It displays the remaining time in an ad break. [Documentation](https://cdn.bitmovin.com/player/ui/3/docs/functions/StringUtils.replaceAdMessagePlaceholders.html) on usage. +- Support for a new placeholder `{adBreakRemainingTime}` in [AdMessageLabel](https://cdn.bitmovin.com/player/ui/3/docs/classes/AdMessageLabel.html) that displays the remaining time in an ad break. [Documentation](https://cdn.bitmovin.com/player/ui/3/docs/functions/StringUtils.replaceAdMessagePlaceholders.html) on usage. ## [3.69.0] - 2024-08-14 ### Added