mirror of
				https://gitea.invidious.io/iv-org/videojs-quality-selector.git
				synced 2024-08-15 00:43:13 +00:00 
			
		
		
		
	PR Modification: Use 'selected' instead of 'isDefault'
This commit is contained in:
		
							parent
							
								
									b4a9aa73d0
								
							
						
					
					
						commit
						26da31607d
					
				
					 2 changed files with 20 additions and 19 deletions
				
			
		|  | @ -13,7 +13,7 @@ | |||
| 
 | ||||
|    <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.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.240p.webm" type="video/webm" label="240P"> | ||||
|    </video> | ||||
|  |  | |||
|  | @ -17,13 +17,11 @@ module.exports = function(videojs) { | |||
|          player.addClass(QUALITY_CHANGE_CLASS); | ||||
| 
 | ||||
|          // Find and set the new selected source
 | ||||
|          // Note: See `setSource` for the reason behind using both 'isDefault'
 | ||||
|          // and 'isdefault'
 | ||||
|          sources = _.map(sources, _.partial(_.omit, _, [ 'isDefault', 'isdefault' ])); | ||||
|          sources = _.map(sources, _.partial(_.omit, _, 'selected')); | ||||
|          selectedSource = _.findWhere(sources, { src: newSource.src }); | ||||
|          // Note: `_.findWhere` returns a reference to an object. Thus the
 | ||||
|          // following updates the original object in `sources`.
 | ||||
|          selectedSource.isDefault = true; | ||||
|          selectedSource.selected = true; | ||||
| 
 | ||||
|          player.src(sources); | ||||
| 
 | ||||
|  | @ -38,31 +36,34 @@ module.exports = function(videojs) { | |||
| 
 | ||||
|       return { | ||||
| 
 | ||||
|          setSource: function(autoSelectedSource, next) { | ||||
|          setSource: function(playerSelectedSource, next) { | ||||
|             var sources = player.currentSources(), | ||||
|                 defaultSource, selectedSource, | ||||
|                 userSelectedSource, chosenSource, | ||||
|                 qualitySelector; | ||||
| 
 | ||||
|             defaultSource = _.find(sources, function(source) { | ||||
|                // While the simplest check would be `!!source.isDefault`, remember that
 | ||||
|                // the sources can come from a `<source>` tag. Therefore, the lowercase
 | ||||
|                // form, `isdefault`, needs to be checked.
 | ||||
|                return source.isDefault === true | ||||
|                   || source.isDefault === 'true' | ||||
|                   || source.isdefault === true | ||||
|                   || source.isdefault === 'true'; | ||||
|             // There are generally two source options, the one that videojs
 | ||||
|             // auto-selects and the one that a "user" of this plugin has
 | ||||
|             // supplied via the `selected` property. `selected` can come from
 | ||||
|             // either the `<source>` tag or the list of sources passed to
 | ||||
|             // videojs using `src()`.
 | ||||
| 
 | ||||
|             userSelectedSource = _.find(sources, function(source) { | ||||
|                // 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
 | ||||
|             qualitySelector = player.controlBar.getChild('qualitySelector'); | ||||
|             if (qualitySelector) { | ||||
|                qualitySelector.setSelectedSource(selectedSource); | ||||
|                qualitySelector.setSelectedSource(chosenSource); | ||||
|             } | ||||
| 
 | ||||
|             // Pass along selected source
 | ||||
|             next(null, selectedSource); | ||||
|             // Pass along the chosen source
 | ||||
|             next(null, chosenSource); | ||||
|          }, | ||||
| 
 | ||||
|       }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue