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

feat(Ads): Allow use a custom playhead tracker in CS #5543

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

avelad
Copy link
Member

@avelad avelad commented Aug 28, 2023

Related to #2792

This is useful because it allows you to implement the use of IMA on platforms that do not support multiple video elements. See #5543 (comment)

@avelad avelad added type: enhancement New feature or request component: ads The issue involves the Shaka Player ads API or the use of other ad SDKs priority: P3 Useful but not urgent labels Aug 28, 2023
@avelad avelad added this to the v4.4 milestone Aug 28, 2023
@github-actions
Copy link
Contributor

Incremental code coverage: No instrumented code was changed.

*
* @description
* Ads configuration.
*
* @property {boolean} customPlayheadTracker
* If this is <code>true</code>, we create a custom playhead tracker for
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to have some details here on why/when you might want this. In the PR description, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I have to admit I'm not sure what this has to do with having multiple video elements?
I tried the change out and it doesn't seem to result in the ad container having a different DOM structure than the regular method.

Copy link
Member Author

Choose a reason for hiding this comment

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

The structure is the same, but the playhead tracker is used to get the position of the original video. If you can only have one video, if you delete it to leave the video to the ad, you stop having the position of the original video, so you can no longer track the position to launch the ads (vmap case)

@joeyparrish
Copy link
Member

Looks fine otherwise.

@avelad
Copy link
Member Author

avelad commented Aug 29, 2023

With the following code implemented on the application side it is possible to support #2792

Using ads.customPlayheadTracker = true

this.eventManager_.listen(this.adManager_, shaka.ads.AdManager.AD_STARTED, (e) => {
  if (e?.originalEvent?.type !== google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED) {
    return;
  }
  if (loadTimeout) {
    clearTimeout(loadTimeout);
  }
  if (prevUrl === undefined && prevTime === undefined) {
    prevUrl = this.player_.getAssetUri();
    if (!this.player_.isLive()) {
      prevTime = this.video_.currentTime;
    }
    this.player_.detach();
    while (this.video_.lastChild) {
      this.video_.removeChild(this.video_.firstChild);
    }
  }
});

this.eventManager_.listen(this.adManager_, shaka.ads.AdManager.AD_STOPPED, (e) => {
  if (e?.originalEvent?.type !== google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED) {
    return;
  }
  if (loadTimeout) {
    clearTimeout(loadTimeout);
  }
  loadTimeout = setTimeout(async () => {
    await this.player_.attach(this.video_, true);
    this.player_.load(prevUrl, prevTime).then(() => {
      externalConfigAfterLoad();
    });
    prevUrl = undefined;
    prevTime = undefined;
  }, 100);
});

The idea is to implement this within ShakaPlayer itself in a future release.

@avelad avelad requested a review from joeyparrish August 29, 2023 07:09
@joeyparrish joeyparrish merged commit 362f03f into shaka-project:main Aug 29, 2023
@avelad avelad deleted the custom-playhead-tracker branch August 29, 2023 17:43
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Oct 28, 2023
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Oct 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: ads The issue involves the Shaka Player ads API or the use of other ad SDKs priority: P3 Useful but not urgent status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants