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

Filter sources type and sort by resolution #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rajczakowsky
Copy link

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.

@sliceofbytes
Copy link

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!

@axten
Copy link

axten commented Apr 3, 2018

Great PR!
we strongly need it, so please merge and release!
@jthomerson

@axten
Copy link

axten commented May 30, 2018

are there any updates on that?
@jthomerson @onebytegone

@cheshir
Copy link

cheshir commented May 2, 2020

Any updates?

Copy link
Contributor

@izkmdz izkmdz left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. 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.
  2. For readability, renaming the res attribute to resolution will help clarify its purpose.
  3. 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 */
Copy link
Contributor

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 */
Copy link
Contributor

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);
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants