Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remaining time in ad break duration #640

Merged
merged 11 commits into from
Aug 21, 2024

Conversation

saravanans-github
Copy link
Contributor

@saravanans-github saravanans-github commented Aug 6, 2024

Description

added support for a new adMessagePlaceholder - adBreakRemainingTime. This placeholder displays the remaining time in an ad break.

Checklist (for PR submitter and reviewers)

  • CHANGELOG entry

Comment on lines 120 to 136
let scheduledAds = player.ads.getActiveAdBreak().ads;
let durations: number[] = [];
let activeAd = player.ads.getActiveAd();
let indexOfActiveAd: number = 0;

for(let i=0; i<scheduledAds.length; i++) {
let iAd = scheduledAds[i];
if(iAd.isLinear) {
durations.push((iAd as LinearAd).duration);

if(iAd.id == activeAd.id) {
indexOfActiveAd = i;
}
}
}
// Compute duration of ads to be played (incl active ad)
let duration = durations.slice(indexOfActiveAd).reduce((prev, current) => prev + current, 0);
Copy link
Member

@dweinber dweinber Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified like this (unless I'm missing something):

Suggested change
let scheduledAds = player.ads.getActiveAdBreak().ads;
let durations: number[] = [];
let activeAd = player.ads.getActiveAd();
let indexOfActiveAd: number = 0;
for(let i=0; i<scheduledAds.length; i++) {
let iAd = scheduledAds[i];
if(iAd.isLinear) {
durations.push((iAd as LinearAd).duration);
if(iAd.id == activeAd.id) {
indexOfActiveAd = i;
}
}
}
// Compute duration of ads to be played (incl active ad)
let duration = durations.slice(indexOfActiveAd).reduce((prev, current) => prev + current, 0);
const duration = player.ads.getActiveAdBreak().ads
.map(ad => ad.duration)
.reduce((prev, current) => prev + current, 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dweinber . I've simplified the code per your guidance.

@felix-hoc
Copy link
Contributor

@saravanans-github please do not alter the PR Checklist - it should stay as-is, because it contains the formal PR requirements. Your changes should be described separately.

Please re-add it, and add a Changelog entry :)

@saravanans-github
Copy link
Contributor Author

thank you @felix-hoc; I've made the change to the PR checklist. Kindly see if that suffices please?

@felix-hoc
Copy link
Contributor

felix-hoc commented Aug 19, 2024

@saravanans-github the CI is still failing. Also, your branch is quite a bit behind main, please pull it in and resolve any conflicts :)

Also, you're still missing the changelog entry

Copy link
Contributor

@felix-hoc felix-hoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, just some nit picks from my side.

Please ensure:

  • your branch is up-to-date with main
  • there are no conflicts
  • the CI passes and the code is properly formatted (your IDE should highlight formatting errors that are identified by TSLint and offer to auto-fix them)
  • you add a changelog entry

Comment on lines 124 to 132
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could be simplified to use a single reduce:

Suggested change
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 duration = player.ads.getActiveAdBreak().ads
.slice(indexOfActiveAd)
.reduce((total, ad) => total + (ad.isLinear ? (ad as LinearAd).duration : 0), 0);

@@ -112,7 +114,28 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
} 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

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
saravanans-github and others added 2 commits August 21, 2024 14:48
Co-authored-by: Felix Hochgruber <felix.hochgruber@bitmovin.com>
Co-authored-by: Felix Hochgruber <felix.hochgruber@bitmovin.com>
Copy link
Contributor

@felix-hoc felix-hoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 😃

@saravanans-github saravanans-github removed the request for review from dweinber August 21, 2024 14:34
@saravanans-github saravanans-github merged commit 5946d04 into develop Aug 21, 2024
3 checks passed
@saravanans-github saravanans-github deleted the remainingTimeInAdBreakDuration branch August 21, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants