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

Return currentSource_.src instead of blob-urls in html5 tech #2232

Closed
wants to merge 5 commits into from

Conversation

imbcmdth
Copy link
Member

@imbcmdth imbcmdth commented Jun 3, 2015

The Flash tech already does this and it makes sense to return the URL of the resource instead of a blob-url if the SourceHandler uses MSE.

@heff
Copy link
Member

heff commented Jun 4, 2015

Awesome.

I was worried we'd have a problem switching to other source handlers an not clearing out the previous currentSource_, but it looks like we always set currentSrc_, so the else wouldn't only be hit when no source has been set.

This does create a difference from the video element we might want to think about. The video element's currentSrc does't return the source that's "next". When you set videoEl.src = 'something' and don't call load(), videoEl.currrentSrc won't return something, whereas I think this new code will.
http://jsbin.com/jupuwituri/2/edit?js,console,output

It's weird, but I think that's the whole reason currentSrc exists instead of just relying on src. See any easy ways to make that work the same?

@imbcmdth
Copy link
Member Author

imbcmdth commented Jun 4, 2015

Gary and I came up with an interesting test: http://jsbin.com/sepajuyada/4/edit

Seems like the currentSrc property is always set even without calling load but is done so asynchronously when the "resource selection algorithm" is executed.

@heff
Copy link
Member

heff commented Jun 4, 2015

Interesting, good find. I always assumed it waited for load(), but clearly not.

I remembered the other reason currentSrc exists, which is that you can set the source via the src attribute or the source child elements. vidEl.src should always return the src attribute value, which will be an empty string if the source was set with children. At the tech level we always set the source with the src property not children, so that's not really a problem for us.

So we could either assume we have more info than the video element in this case and return the set source as currentSrc immediately, or try to mimic the asynchronous side of it so it matches exactly with how the video element works, returning the previous source for any synchronous calls to currentSrc. Any other thoughts?

I added on to the jsbin to test some things. You can comment out the source child block to see how that works a little differently.
http://jsbin.com/wulomalopu/1/edit?js,console,output

Some other notes...

When you set an empty string as a source, you'll see there's some differences there. The src attribute will return the absolute URL of the page, while currentSrc will return an empty string in Firefox and Safari, or the previous source URL in Chrome. Go figure.

It looks like the loadstart event should fire before currentSrc is updated, but the browsers are either ignoring that or setting it in parallel before the listener gets to it.

@imbcmdth
Copy link
Member Author

imbcmdth commented Jun 5, 2015

I tried to capture the asynchronous behavior that you mentioned in a test and made some changes to media to emulate that behavior. I think I may have gone too far with the way I handle src when it is an empty string. It's probably best to just allow currentSrc_ to be set to an empty string as well since that seems to be the majority behavior.

if (source && source.src !== '') {
tech.currentSource_ = source;
}
}, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. If you use this.setTimeout it will automatically kill the timeout when the tech is disposed. Just to clean up.

Adding async always makes me worried about edge cases we're not thinking of... I can't think of anything specific though so we could pull this in and see how it goes. @videojs/core-committers any final opinions on this (setting currentSrc asynchronously or not)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this matches <video> behavior better, I think it's the way to go. +1 to this.setTimeout.

@dmlap
Copy link
Member

dmlap commented Jun 5, 2015

Two small comments but otherwise LGTM

// asynchronous execution of the `resource selection algorithm`
this.setTimeout(function () {
if (source && source.src !== '') {
tech.currentSource_ = source;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should bind this method instead of using the tech variable.

@gkatsev
Copy link
Member

gkatsev commented Jun 9, 2015

Minor comment, otherwise, LGTM.

@gkatsev
Copy link
Member

gkatsev commented Jun 9, 2015

LGTM

gkatsev pushed a commit to gkatsev/video.js that referenced this pull request Jun 10, 2015
@gkatsev
Copy link
Member

gkatsev commented Jun 10, 2015

Closed via 20b46b9

@gkatsev gkatsev closed this Jun 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants