-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot set startTime on Safari-handled HLS content after loading it again #4244
Comments
Often you don't know if an event has already fired before you start listening for it. With media lifecycle events, the In the case where the state has already been reached, perhaps the utility should call the callback asynchronously (after a Promise) instead of synchronously before returning. I think that would solve it by deferring that callback until the next interpreter cycle. An alternate fix could be to change the @alexandercerutti, would you be willing to test patches/branches for me to make sure these proposed fixes work? I don't have an iPhone or Mac available at home to test this. |
Here are two possible fixes:
I expect both to work, but I think I prefer the addition of the new method. If that fix works, I think that is the one I'd prefer to merge. |
Hey @joeyparrish, thanks for your reply and your possible fixes! I'm going to test them asap. I'm not quite sure if the best way to test them is by changing the compiled code or to recompile it from scratch and replace I'm not quite sure how to start in case of compilation. Is there any document I can refer to? I was looking in the repo but I wasn't able to find it. May I also propose to create a Github Wiki with documentation? |
Documentation is built from the /docs/ folder and lives in https://shaka-player-demo.appspot.com/docs/api/ Compilation is documented briefly in https://shaka-player-demo.appspot.com/docs/api/tutorial-welcome.html The short version is: python build/all.py Output goes to dist/ I hope that helps! |
Thanks @joeyparrish! I tried to compile both solutions (but yet I have to test them, I'll do as soon as my test iPhone will have enough charge 😝). Promise solution built correctly, but the other one failed with this error: |
I don't know, I was testing with my work custom application which compiles with Webpack 4. What's weird is that if I try to compile Promise fix, Webpack will output invalid characters: u
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))ndefinedundefinedundefinedundefinedundefined
EDIT: This issue seems to happen only with Webpack 4 but not with Webpack 5. So, it's okay, cause it might be our "excuse" to update to Webpack 5. Now I have to test the Promise solution. |
Uhm, there's something weird happening with Promise fix. I mean, through some breakpoints I can see that the order issue is fixed and But still, the content starts from 0, and now I have to understand on which side this happens. I've found this and I think this might be the reason (I have to do some tests - I'll try to change the code and recompile and report it back): https://stackoverflow.com/questions/18266437/html5-video-currenttime-not-setting-properly-on-iphone I see that in shaka-player/lib/media/playhead.js Lines 88 to 94 in b70938c
I guess there might be something else to be done (like what I've proposed above) to create a complete solution... maybe instead of setting the time there, setting it on EDIT: Yes, that worked. I've changed this.eventManager_.listenOnce(this.mediaElement_, 'seeking', () => {
this.started_ = true;
});
- const currentTime = this.mediaElement_.currentTime;
- // Using the currentTime allows using a negative number in Live HLS
- const newTime = Math.max(0, currentTime + this.startTime_);
- this.mediaElement_.currentTime = newTime;
+
+ this.eventManager_.listenOnce(this.mediaElement_, 'loadeddata', () => {
+ const currentTime = this.mediaElement_.currentTime;
+ // Using the currentTime allows using a negative number in Live HLS
+ const newTime = Math.max(0, currentTime + this.startTime_);
+ this.mediaElement_.currentTime = newTime;
+ }); At this point, this solution should be tested everywhere (and I'm going to test it on desktop Browser at least). After building issues have been solved on the second solution and I test that everything is okay, I might create a Pull Request if you want. EDIT 2: On Chrome and Firefox Desktop, this change seems to work fine as well, but Safari Desktop seems to break... :/ EDIT 3: I've tried a different approach. I've moved the listener to @@ -88,10 +88,6 @@ shaka.media.SrcEqualsPlayhead = class {
this.eventManager_.listenOnce(this.mediaElement_, 'seeking', () => {
this.started_ = true;
});
- const currentTime = this.mediaElement_.currentTime;
- // Using the currentTime allows using a negative number in Live HLS
- const newTime = Math.max(0, currentTime + this.startTime_);
- this.mediaElement_.currentTime = newTime;
}
};
@@ -100,6 +96,13 @@ shaka.media.SrcEqualsPlayhead = class {
this.eventManager_, () => {
onLoaded();
});
+
+ this.eventManager_.listenOnce(this.mediaElement_, 'loadeddata', () => {
+ const currentTime = this.mediaElement_.currentTime;
+ // Using the currentTime allows using a negative number in Live HLS
+ const newTime = Math.max(0, currentTime + this.startTime_);
+ this.mediaElement_.currentTime = newTime;
+ }); |
@joeyparrish can you review the last comment? |
@joeyparrish do you have any news about this? This is blocking a more-than-actual production issue (and report) on our product. Should I open a Pull Request? In case, I'd be happy to. If so, against which branch? |
Any PR are welcome! Always against main branch! Thanks! |
Oh, wait. Now I'm remembering: I wasn't able to test the second fix possibility. So I can open a PR for Promise fix only. I'm not sure this is actually okay as @joeyparrish expressed preference for the second solution. |
@joeyparrish any news? What should be fixed on the second sample so it can be tested? |
Hey @joeyparrish, were you able to give a look to this? Thank you very much! |
@joeyparrish Can you review it again? if i remember correctly... you have two branches in your fork about this issue. |
Hey @joeyparrish @avelad, I finally had the chance to put my hands on this again and I tried to make things work. Now I'm of the idea that the "method way" @joeyparrish proposed is the best way. I had to add a missing |
…dia.Playhead for start time operations
…dia.Playhead for start time operations
A new method `shaka.media.Playhead.ready` has been added for start time operations. Fixes #4244
A new method `shaka.media.Playhead.ready` has been added for start time operations. Fixes #4244
A new method `shaka.media.Playhead.ready` has been added for start time operations. Fixes #4244
A new method `shaka.media.Playhead.ready` has been added for start time operations. Fixes #4244
A new method `shaka.media.Playhead.ready` has been added for start time operations. Fixes #4244
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?
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
asstartTime
in.load()
..load
call is centralized such as: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:
this.started_
onLoaded()
, which gets executed when the media is in ready state and setsthis.started_
totrue
.setStartTime(startTime)
method, which usesthis.started_
to update the startTimeIn
player.js
,onSrcEquals_
executes this:and expects that
onLoaded()
inSrcEqualsPlayhead
will get called asynchronously but it may happen (especially on iOS, but it happened once also on Mac) that the function is called beforesetStartTime
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!
The text was updated successfully, but these errors were encountered: