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

src() called as a getter should return the video src #968

Merged
merged 1 commit into from
Mar 4, 2014

Conversation

dmlap
Copy link
Member

@dmlap dmlap commented Jan 26, 2014

It can be handy that src() returns the player object when it is invoked but it does not match the behavior of the corresponding property on the video element. Ignoring the spec however, while the video element is running the resource selection algorithm, currentSrc may be undefined. If the video source has been specified through an attribute on the video element, src() is the natural way to expose that URL programmatically. Without this change, it's necessary to bypass the player and interact with the tech directly to determine the value of the src attribute.

@heff
Copy link
Member

heff commented Jan 26, 2014

Here's my understanding: videoElement.src returns the value of the src attribute on the video tag. This may be different from videoElement.currentSrc which returns the selected source, whether provided by the attribute or source tags. i.e. if only source tags are used, videoElement.src returns nothing.

It never really made sense to provide a src() getter because only source tags have been used with video.js (the src attribute on the video tag should work, but doesn't yet). Which means src() would always return nothing if following the spec. So currentSrc() has been the appropriate getter.

Can you go deeper into the use case where currentSrc is failing?

It sounds like something is setting src(), and then something different would be immediately getting currentSrc(), and while it should be fast, the async nature of src -> currentSrc is causing an issue.

techGet('src') works well in your change because we're relying on the src attribute in the underlying video element. If we decided to pass through the source tags to the underlying video element for some reason, this method would break. That may never happen, but it's worth noting.

@@ -1069,7 +1073,7 @@ vjs.Player.prototype.src = function(source){
}
}
}
return this;
return source;
Copy link
Member

Choose a reason for hiding this comment

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

This return will always happen after a setter now that you've added code for a getter. All other video.js API setters return this for chaining. Is there a reason this needs to return the source value?

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this return to match the behavior of the src property on the video element. As long as the getter behavior is available, keeping the original behavior of the setter for consistency would be ok with me.

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool, let's keep it returning this here then.

@heff
Copy link
Member

heff commented Jan 28, 2014

Can you go deeper into the use case where currentSrc is failing?

Any more details on this?

@dmlap
Copy link
Member Author

dmlap commented Jan 29, 2014

I was working on the HLS plugin and wanted it to conditionally activate if the video source looked like an m3u8. Here's a simplified example. I didn't notice the lack of src attribute support at init time. Using source child elements would break this strategy but I figured this allows the plugin to act more like a polyfill in simple cases and that's a benefit even if the multi-source configuration requires a little extra ceremony.

@heff
Copy link
Member

heff commented Feb 11, 2014

The source attribute on the video tag isn't really supported anyway (something we should fix). In this modified example I just switched the embed code to use source tags, and the example works.
http://jsfiddle.net/heff/sxr96/1/

Would that cover the issue you were having, or no?

@heff
Copy link
Member

heff commented Feb 11, 2014

Nvm, reread your last comment that said using source child elements would break the strategy. I'm interested to know the use case where you'd set the src attribute and not call the src() API method.

Either way it sounds like making the src attribute work would be the best first step here?

src;
src = player.src();

notEqual(src, player, 'the player is not returned');
Copy link
Member

Choose a reason for hiding this comment

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

@dmlap just a heads up, this doesn't actually test anything except that the stub is working. :) Actually Flash would break for this test if it wasn't mocked, because flash.src doesn't return anything. Fixing it now and pulling this in.

@heff heff mentioned this pull request Feb 28, 2014
Made the src method return the player when setting
@heff heff merged commit f155814 into videojs:master Mar 4, 2014
@dmlap dmlap deleted the bugfix/src-getter branch March 7, 2014 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: more info Please make enough detailed information is added to be actionable.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants