-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Order of attachMedia and loadSource calls is inconsistent in docs and causes inconsistent results #4952
Comments
Just to provide code examples for the scenarios outlined by @jeffometer above... When using 1.2.3, we tried using what was outlined in the docs for the 1.2.3 version (binding the manifest parsed listener from within the MEDIA_ATTACHED event and also calling hls.loadSource). This did not work (thus we chose to upgrade to 1.2.4):
When using 1.2.4 we also tried what was outlined in the docs. This did not work:
This is the solution that worked every time with 1.2.4 (calling attachMedia from within event listener for manifest parsed event):
|
Can you clarify what is meant by not reaching media attached? The nesting was removed from the docs because:
The media element does not need to be attached for a stream to begin loading. Media should be detached however before loading a new stream in order to reset player state. The player does this automatically in loadSource. So, it is best practice to not call loadSource in a player event callback. |
Hi Rob. I mean that the MEDIA_ATTACHED event never fires, the video source never gets set, and the readyState remains at 0. FWIIW, we do not get any error events, so it seems something failed to occur as opposed to something going wrong. Your explanation makes perfect sense. However we still were only able to get consistent correct results by putting the attachMedia call in the MANIFEST_PARSED callback. Perhaps there is another issue causing a race condition? But we were unable to discover it. Unfortunately we don't have an easily reproducible sandbox example, but you can see it in a public debugging room on our product at https://standups.staging.geometer.dev/geometer-io/public-debugging-room/recordings/2230. You'll have to log in via Google to see it though. Directly under the video element is a script tag with the following content:
We also have other js on that page (via alpine.js) which watches the video readyState, and the whole page is server rendered (via Elixir LiveView). Thanks! |
I would need a sandbox example to reproduce. Thanks. |
Wanted to comment that I was seeing a similar issue. Here are some details.
|
Check that the internal protected onMediaAttaching(
event: Events.MEDIA_ATTACHING,
data: MediaAttachingData
) {
const media = (this.media = data.media);
if (media && MediaSource) {
const ms = (this.mediaSource = new MediaSource());
// MediaSource listeners are arrow functions with a lexical scope, and do not need to be bound
ms.addEventListener('sourceopen', this._onMediaSourceOpen);
// link video and media Source
media.src = self.URL.createObjectURL(ms);
// Setting the src should invoke this callback unless replaced:
private _onMediaSourceOpen = () => {
const { hls, media, mediaSource } = this;
logger.log('[buffer-controller]: Media source opened');
if (media) {
this.updateMediaElementDuration();
hls.trigger(Events.MEDIA_ATTACHED, { media });
} You probably want to make sure that something else isn't setting (or clearing)
So if you see another "emptied" after "loadstart" then you've got something else in your application interfering with the video element. So you might want to attach on "emptied" or MANIFEST_PARSED (which ever comes first). |
v1.3.3 includes changes in #5206 based on the concept above. If the media element dispatches "emptied" while attaching, and
This won't "fix" the issue, because the issue is not with HLS.j when something external modifies the src attribute on the media element. Add your own "emptied" listener or defer attaching until your app and its libs are done with the media element. |
What do you want to do with Hls.js?
The docs in https://github.com/video-dev/hls.js/blob/v1.2.3/docs/API.md#third-step-load-a-manifest show indicates a nesting of attachMedia and loadSource based on the MEDIA_ATTACHED event. But the version for 1.2.4 calls these methods synchronously.
At first I though this indicated a breaking change, but what I observed seemed to indicate some general confusing flakiness. Here is what I observed:
Under 1.2.3 nesting as in the docs as in the docs sometimes worked but sometimes did not reach the MEDIA_ATTACHED event.
Under 1.2.4 calling synchronously as in the docs sometimes worked but also sometimes did not reach the MEDIA_ATTACHED event.
Under 1.2.4 nesting the attachMedia under the MANIFEST_PARSED event seems to work every time (note this is different from the docs for both 1.2.3. and 1.24)
Should it matter how these get called? Is the flakiness an internal error or something weird in my setup? Thanks for helping clarify.
What have you tried so far?
No response
The text was updated successfully, but these errors were encountered: