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

Detach/re-attach to the video element on client-side ads for devices that don't support multiple media elements #2792

Closed
ismena opened this issue Aug 13, 2020 · 4 comments · Fixed by #6575
Assignees
Labels
component: ads The issue involves the Shaka Player ads API or the use of other ad SDKs platform: Cast Issues affecting Cast devices platform: Tizen Issues affecting Tizen platform: TV/STB Issues affecting smart TV or set-top box platforms platform: WebOS Issues affecting WebOS priority: P2 Smaller impact or easy workaround status: archived Archived and locked; will not be updated type: enhancement New feature or request
Milestone

Comments

@ismena
Copy link
Contributor

ismena commented Aug 13, 2020

Some device types don't support multiple video elements on the page and CS IMA has to reuse the same video element to show ads. (Tizen, WebOS)
For this scenario, we need to detach from the <video> and re-attach after the ads has finished playing.
IMA has an isCustomPlaybackUsed method that we can call to check if the media element is gonna be reused (true if the method returns true :)).

We can call it when we get a content pause is requested by the SDK, and detach from the element if need be.

We'll need to save video.currentTime to be able to resume playback once the ads are done playing.

@bruno-sartori
Copy link

Any updates on this?

joeyparrish pushed a commit that referenced this issue Aug 29, 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)
Robloche pushed a commit to Robloche/shaka-player that referenced this issue Nov 30, 2023
)

Related to shaka-project#2792

This is useful because it allows you to implement the use of IMA on
platforms that do not support multiple video elements. See
shaka-project#5543 (comment)
@Boubalou
Copy link
Contributor

Boubalou commented Mar 21, 2024

While implementing this logic on our end while waiting for this to be provided within Shaka, we faced an issue where track IDs upon a detach/attach flow would change and get incremented, leading to our comparison to re-select the previous selected text track to be broken.

It would be nice to keep that in mind or allow a way to reset that state of IDs when re-attaching the player with the same manifest after an ad.

@avelad
Copy link
Member

avelad commented Apr 2, 2024

I plan to implement this as soon as the Preload API is working correctly for unload

@avelad
Copy link
Member

avelad commented May 9, 2024

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

Using ads.customPlayheadTracker = true and v.4.8 or above

this.eventManager_ = new shaka.util.EventManager();
const adManager = this.player_.getAdManager();
const preloadTimer = new shaka.util.Timer(async () => {
  if (prevPreload) {
    await this.player_.attach(this.video_, true);
    this.player_.load(prevPreload)
    prevPreload = undefined;
  }
});
let prevPreload;
this.eventManager_.listen(adManager, shaka.ads.AdManager.AD_STARTED, async (e) => {
  if (e?.originalEvent?.type == google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED) {
    preloadTimer.stop();
    if (!prevPreload) {
      prevPreload = await this.player_.unloadAndSavePreload(false, true);
      this.player_.detach(true);
    }
  }
});
this.eventManager_.listen(adManager, shaka.ads.AdManager.AD_STOPPED, (e) => {
  if (e?.originalEvent?.type == google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED) {
    preloadTimer.tickAfter(0.1);
  }
});

@avelad avelad self-assigned this May 9, 2024
@avelad avelad modified the milestones: Backlog, v4.9 May 9, 2024
@avelad avelad added platform: Cast Issues affecting Cast devices platform: TV/STB Issues affecting smart TV or set-top box platforms labels May 10, 2024
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Jul 22, 2024
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Jul 22, 2024
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 platform: Cast Issues affecting Cast devices platform: Tizen Issues affecting Tizen platform: TV/STB Issues affecting smart TV or set-top box platforms platform: WebOS Issues affecting WebOS priority: P2 Smaller impact or easy workaround status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants