-
Notifications
You must be signed in to change notification settings - Fork 53
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
Filter sources type and sort by resolution #10
base: master
Are you sure you want to change the base?
Conversation
Thank you very much. I love when I'm about to custom write something and I find a perfect pull request already exists! Much appreciated! |
Great PR! |
are there any updates on that? |
Any updates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request. This feature will be very useful. Here are some notes to make it as complete as it can be for developers using this plugin.
@@ -54,18 +54,35 @@ module.exports = function(videojs) { | |||
this.update(); | |||
}, | |||
|
|||
orderSources: function(a, b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Instead of using a public sort method for
orderSources
, perhaps it would be more appropriate to make it a locally-scoped anonymous function like the one in.filter
on line 74. - For readability, renaming the
res
attribute toresolution
will help clarify its purpose. - If one or more sources do not have the
resolution
attribute, we should keep the sources in the same order.
singleTypeSources, | ||
orderedSources; | ||
|
||
/* filter sources by the current type on the player */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion, we prefer to start comments with //
instead of using /* */
. Thanks!
return item.type === player.currentType(); | ||
}); | ||
|
||
/* sort sources by res attributed if exist */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo, by res attributed if exist
can be changed to by resolution attribute if it exists
@@ -54,18 +54,35 @@ module.exports = function(videojs) { | |||
this.update(); | |||
}, | |||
|
|||
orderSources: function(a, b) { | |||
if (a.res && b.res) { | |||
return parseFloat(a.res) - parseFloat(b.res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, can the sort order be descending with the largest resolution at the top? Thanks!
This small addition allows you to use this plugin with multiple types of videos ( for example mp4 and webm ) and also order the labels by passing additional argument of "res" for resolution (that is optional ).
Filtering by type:
Functionality checks the current type on the player and then filters the sources by the type so you not ending up with duplicated labels for each source type.
Sorting by resolution:
The part for sorting labels checks if the argument of "res" exist and if it is it orders the labels by values of that attribute for example [{ lebel: High, res: 1400 }, { lebel: Low, res: 360 }, { lebel: Medium, res: 750 } ], so menu alway be Low, Medium, High. If there is no "res" it diplays the order as it comes.
All those changes are very helpful for the plugin to be used with multiple types and in conjunction with plugins like Language Switch where you replace sources depending on language selection and then quality labels order is all random.