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

Loadstart event is triggered twice #1491

Closed
RavWar opened this issue Jul 11, 2016 · 8 comments
Closed

Loadstart event is triggered twice #1491

RavWar opened this issue Jul 11, 2016 · 8 comments

Comments

@RavWar
Copy link

RavWar commented Jul 11, 2016

Observed behaviour

Loadstart event is triggered twice on dash source initialization. It's currently incompatible with some of the latest videojs versions (videojs/video.js#3428)

Console output

loadstart

@dsparacio dsparacio added this to the v2.3.0 milestone Jul 11, 2016
@davemevans
Copy link
Contributor

davemevans commented Jul 12, 2016

This only occurs when setting a <source> child on the <video> as in the linked example above. Using the reference player, or other players which create the dash.js instance/attach the source programmatically, only a single loadstart will be triggered.

The loadstart event is triggered by the <video> tag whenever a media source is selected (see Step 8 of Resource Selection Algorithm in [1]). In the linked example, this happens at load time, when the HTML is loaded (because of the <source> tag), and again when dash.js attaches the MediaSource object via video.src.

The UA behaviour described seems to be compliant with the spec, and not caused specifically by dash.js, except in one specific case.

[1] https://www.w3.org/TR/html5/embedded-content-0.html#loading-the-media-resource

(edit) additionally there is a bug which occasionally causes a third loadstart. see #1491 (comment)

@RavWar
Copy link
Author

RavWar commented Jul 13, 2016

Some further testing with a bit different setup:
http://jsbin.com/beziyodave/1/edit?html,console,output

Here i've seen different outcomes:

1 loadstart event (with disabled browser cache almost never happens)
test

2 loadstart events
test1

3 loadstart events
test2

3 loadstart events (a bit different)
test3

This unstable behavior is exactly what i'm experiencing in latest videojs+dash while using source elements and https://github.com/videojs/videojs-contrib-dash (which sets the source programmatically just like in this example). I could find a workaround for this issue, but i'm afraid this would not limit only to my case.

Also, i'm not sure whether it's appropriate to compare with HLS or not, but here it goes:
http://jsbin.com/laxiwogure/edit?html,console,output
Always getting 1 loadstart event.

@davemevans
Copy link
Contributor

davemevans commented Jul 13, 2016

Some of the logs in the comment above make it clearer what is happening - there are two player instances here, at least some of the time.

It turns out that, when presented with a <source> tag containing type type='application/dash+xml', dash.js will always attempt to start automatically unless window.dashjs.skipAutoCreate is true (https://github.com/Dash-Industry-Forum/dash.js/blob/development/src/streaming/MediaPlayerFactory.js#L103). This is always undefined currently, so the handler will be registered. This is probably a bug an undocumented feature in dash.js.

video.js creates a player programmatically, attaches the source and starts, which is how we expect it to work, and all is good - the MediaSource is attached, loadstart is triggered (once).

Subsequently, the load event triggers and the handler mentioned above runs and creates another player which sets the source tag on the media element, causing a second loadstart.

However, it isn't clear why this isn't happening in the original console log, or the first in the previous comment so more investigation may be required since there may be another issue here.

@davemevans
Copy link
Contributor

As expected, the initial problem was indeed caused by the <source> tag even existing. See this example which contains no dash.js or video.js: https://jsfiddle.net/jzk1sod9/

At least in Chrome on Win7, loadstart is always fired.

@davemevans
Copy link
Contributor

As a workaround for the third loadstart (all but the first in #1491 (comment)) could add:

    this.el_._dashjs_player = this.mediaPlayer_;

immediately after this.mediaPlayer_ has been initialised.

@davemevans
Copy link
Contributor

Looks like the intended way to disable auto-creation is to add the following to the HTML before dash.js is included:

<script> window.dashjs = { skipAutoCreate: true }; </script>

Source: #1138 (comment)

@davemevans
Copy link
Contributor

I have created #1496 to track the problem with three loadstart events, and I think it has been shown (#1491 (comment)) that two is valid behaviour according to HTML5 when using Media Source Extensions.

Can this issue be closed?

@RavWar
Copy link
Author

RavWar commented Jul 14, 2016

Yep, all clear now, though a bit unfortunate that videojs+dash+source tags cannot exist together atm. Maybe something can be done in videojs to support multiple loadstart events, we'll see.
@bbcrddave thank you for your investigations in this matter!

@RavWar RavWar closed this as completed Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants