mirror of
https://github.com/iv-org/videojs-quality-selector.git
synced 2025-04-26 02:09:10 -04:00
PR Modification: Use 'selected' instead of 'isDefault'
This commit is contained in:
parent
b4a9aa73d0
commit
26da31607d
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<video id="video_1" class="video-js vjs-default-skin" controls preload="auto" data-setup='{}'>
|
<video id="video_1" class="video-js vjs-default-skin" controls preload="auto" data-setup='{}'>
|
||||||
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.720p.webm" type="video/webm" label="720P">
|
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.720p.webm" type="video/webm" label="720P">
|
||||||
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.480p.webm" type="video/webm" label="480P" isdefault="true">
|
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.480p.webm" type="video/webm" label="480P" selected="true">
|
||||||
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.360p.webm" type="video/webm" label="360P">
|
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.360p.webm" type="video/webm" label="360P">
|
||||||
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.240p.webm" type="video/webm" label="240P">
|
<source src="https://upload.wikimedia.org/wikipedia/commons/transcoded/a/ab/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm/Caminandes_3_-_Llamigos_-_Blender_Animated_Short.webm.240p.webm" type="video/webm" label="240P">
|
||||||
</video>
|
</video>
|
||||||
|
@ -17,13 +17,11 @@ module.exports = function(videojs) {
|
|||||||
player.addClass(QUALITY_CHANGE_CLASS);
|
player.addClass(QUALITY_CHANGE_CLASS);
|
||||||
|
|
||||||
// Find and set the new selected source
|
// Find and set the new selected source
|
||||||
// Note: See `setSource` for the reason behind using both 'isDefault'
|
sources = _.map(sources, _.partial(_.omit, _, 'selected'));
|
||||||
// and 'isdefault'
|
|
||||||
sources = _.map(sources, _.partial(_.omit, _, [ 'isDefault', 'isdefault' ]));
|
|
||||||
selectedSource = _.findWhere(sources, { src: newSource.src });
|
selectedSource = _.findWhere(sources, { src: newSource.src });
|
||||||
// Note: `_.findWhere` returns a reference to an object. Thus the
|
// Note: `_.findWhere` returns a reference to an object. Thus the
|
||||||
// following updates the original object in `sources`.
|
// following updates the original object in `sources`.
|
||||||
selectedSource.isDefault = true;
|
selectedSource.selected = true;
|
||||||
|
|
||||||
player.src(sources);
|
player.src(sources);
|
||||||
|
|
||||||
@ -38,31 +36,34 @@ module.exports = function(videojs) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
setSource: function(autoSelectedSource, next) {
|
setSource: function(playerSelectedSource, next) {
|
||||||
var sources = player.currentSources(),
|
var sources = player.currentSources(),
|
||||||
defaultSource, selectedSource,
|
userSelectedSource, chosenSource,
|
||||||
qualitySelector;
|
qualitySelector;
|
||||||
|
|
||||||
defaultSource = _.find(sources, function(source) {
|
// There are generally two source options, the one that videojs
|
||||||
// While the simplest check would be `!!source.isDefault`, remember that
|
// auto-selects and the one that a "user" of this plugin has
|
||||||
// the sources can come from a `<source>` tag. Therefore, the lowercase
|
// supplied via the `selected` property. `selected` can come from
|
||||||
// form, `isdefault`, needs to be checked.
|
// either the `<source>` tag or the list of sources passed to
|
||||||
return source.isDefault === true
|
// videojs using `src()`.
|
||||||
|| source.isDefault === 'true'
|
|
||||||
|| source.isdefault === true
|
userSelectedSource = _.find(sources, function(source) {
|
||||||
|| source.isdefault === 'true';
|
// Must check for both boolean and string 'true' as sources set
|
||||||
|
// programmatically should use a boolean, but those coming from
|
||||||
|
// a `<source>` tag will use a string.
|
||||||
|
return source.selected === true || source.selected === 'true';
|
||||||
});
|
});
|
||||||
|
|
||||||
selectedSource = defaultSource || autoSelectedSource;
|
chosenSource = userSelectedSource || playerSelectedSource;
|
||||||
|
|
||||||
// Update the quality selector with the new source
|
// Update the quality selector with the new source
|
||||||
qualitySelector = player.controlBar.getChild('qualitySelector');
|
qualitySelector = player.controlBar.getChild('qualitySelector');
|
||||||
if (qualitySelector) {
|
if (qualitySelector) {
|
||||||
qualitySelector.setSelectedSource(selectedSource);
|
qualitySelector.setSelectedSource(chosenSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass along selected source
|
// Pass along the chosen source
|
||||||
next(null, selectedSource);
|
next(null, chosenSource);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user