shaka-player: Cannot set startTime on Safari-handled HLS content after loading it again

Have you read the FAQ and checked for duplicate open issues?

Yes, none found

What version of Shaka Player are you using?

3.3.4, 3.3.5

Can you reproduce the issue with our latest release version?

Yes

Can you reproduce the issue with the latest code from main?

Not tested

Are you using the demo app or your own custom app?

Custom App

If custom app, can you reproduce the issue using our demo app?

I guess it cannot be tested (see below for the reason).

What browser and OS are you using?

Safari 15, iOS 15 and MacOS 12.2.1 (see differences below)

For embedded devices (smart TVs, etc.), what model and firmware version are you using?

What are the manifest and license server URIs?

I don’t know yet if I can provide one (cause they are owned by our client). I’ll provide via mail if needed

What configuration are you using? What is the output of player.getConfiguration()?

What did you do?

  • load a (clean for sure) HLS content with startTime not specified or to 0 and leave it go for a few seconds.
  • unload the content
  • load the content back again with a startTime

What did you expect to happen?

The content should start from the specified point

What actually happened?

Content starts again from 0


I’ve investigated a bit what is happening under the hood and it seems like there’s kind of race condition issue that happens on Safari iOS but not on Safari MacOS.

My use case is what follows: we load a content and at a certain point we might have an AD midroll. Hence, we unload the content and give Video node control to our AD Provider’s SDK.

Then, we give back Video node control to Shaka, by passing to it the latest currentTime as startTime in .load().

.load call is centralized such as:

await this.player.load(content.src, content.startPosition, content.mimeType);

But when this is executed on Safari iOS, the startTime is ignored. Deep diving inside shaka, I’ve found there’s an utility, that is being used, shaka.media.SrcEqualsPlayhead, which gets created everytime the content is loaded.

This class owns these notable things:

  • Instance variable this.started_
  • onLoaded(), which gets executed when the media is in ready state and sets this.started_ to true.
  • setStartTime(startTime) method, which uses this.started_ to update the startTime

In player.js, onSrcEquals_ executes this:

this.playhead_ = new shaka.media.SrcEqualsPlayhead(mediaElement);

...

if (has.startTime != null) {
  this.playhead_.setStartTime(has.startTime);
}

and expects that onLoaded() in SrcEqualsPlayhead will get called asynchronously but it may happen (especially on iOS, but it happened once also on Mac) that the function is called before setStartTime could get called. Therefore startTime setting is ignored.

I guess that onLoaded() could be moved into a Promise that will always resolve asynchronously but I’m not very into the codebase, so I don’t know if it could be the right solution.

I’m available for any clarification if needed. Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

@joeyparrish Can you review it again? if i remember correctly… you have two branches in your fork about this issue.

Any PR are welcome! Always against main branch! Thanks!