mirror of
				https://github.com/videojs/video.js.git
				synced 2025-10-31 00:08:01 +02:00 
			
		
		
		
	## Description It is useful to have methods for appending and removing `<source>` elements to the `<video>` element, as they are sometimes required to enable certain playback features, for example, using [Airplay with MSE](https://webkit.org/blog/15036/how-to-use-media-source-extensions-with-airplay). ## Specific Changes proposed Add new methods-- `addSourceElement()` and `removeSourceElement()` to the player and tech. The former will take a source object and create and append a new `<source>` element to the `<video>` element, and the latter will take a source url and remove any `<source>` element with a matching `src`. ## Requirements Checklist - [ ] Feature implemented / Bug fixed - [ ] If necessary, more likely in a feature request than a bug fix - [ ] Change has been verified in an actual browser (Chrome, Firefox, IE) - [ ] Unit Tests updated or fixed - [ ] Docs/guides updated - [ ] Example created ([starter template on JSBin](https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0)) - [ ] Has no DOM changes which impact accessiblilty or trigger warnings (e.g. Chrome issues tab) - [ ] Has no changes to JSDoc which cause `npm run docs:api` to error - [ ] Reviewed by Two Core Contributors
		
			
				
	
	
		
			184 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // Fake a media playback tech controller so that player tests
 | |
| // can run without HTML5 which PhantomJS does not support.
 | |
| import Tech from '../../../src/js/tech/tech.js';
 | |
| import {createTimeRanges} from '../../../src/js/utils/time.js';
 | |
| /**
 | |
|  * @class
 | |
|  */
 | |
| class TechFaker extends Tech {
 | |
| 
 | |
|   constructor(options, handleReady) {
 | |
|     super(options, handleReady);
 | |
| 
 | |
|     this.featuresPlaybackRate = true;
 | |
|     this.defaultPlaybackRate_ = 1;
 | |
|     this.playbackRate_ = 1;
 | |
|     this.currentTime_ = 0;
 | |
| 
 | |
|     if (this.options_ && this.options_.sourceset) {
 | |
|       this.fakeSourceset();
 | |
|     }
 | |
|     if (!options || options.autoReady !== false) {
 | |
|       this.triggerReady();
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   createEl() {
 | |
|     const el = super.createEl('div', {
 | |
|       className: 'vjs-tech'
 | |
|     });
 | |
| 
 | |
|     return el;
 | |
|   }
 | |
| 
 | |
|   // fake a poster attribute to mimic the video element
 | |
|   poster() {
 | |
|     return this.el().poster;
 | |
|   }
 | |
|   setPoster(val) {
 | |
|     this.el().poster = val;
 | |
|     this.trigger('posterchange');
 | |
|   }
 | |
| 
 | |
|   setControls(val) {}
 | |
| 
 | |
|   setVolume(value) {
 | |
|     this.volume_ = value;
 | |
|   }
 | |
| 
 | |
|   setMuted() {}
 | |
| 
 | |
|   setDefaultMuted() {}
 | |
| 
 | |
|   setAutoplay(v) {
 | |
|     if (!v) {
 | |
|       this.options_.autoplay = false;
 | |
|     }
 | |
| 
 | |
|     this.options_.autoplay = true;
 | |
|   }
 | |
| 
 | |
|   defaultPlaybackRate(value) {
 | |
|     if (value !== undefined) {
 | |
|       this.defaultPlaybackRate_ = parseFloat(value);
 | |
|     }
 | |
|     return this.defaultPlaybackRate_;
 | |
|   }
 | |
| 
 | |
|   setPlaybackRate(value) {
 | |
|     const last = this.playbackRate_;
 | |
| 
 | |
|     this.playbackRate_ = parseFloat(value);
 | |
| 
 | |
|     if (value !== last) {
 | |
|       this.trigger('ratechange');
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   playbackRate() {
 | |
|     return this.playbackRate_;
 | |
|   }
 | |
| 
 | |
|   setCurrentTime(value) {
 | |
|     const last = this.currentTime_;
 | |
| 
 | |
|     this.currentTime_ = parseFloat(value);
 | |
| 
 | |
|     if (value !== last) {
 | |
|       this.trigger('timeupdate');
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   currentTime() {
 | |
|     return this.currentTime_;
 | |
|   }
 | |
| 
 | |
|   seekable() {
 | |
|     return createTimeRanges(0, 0);
 | |
|   }
 | |
|   seeking() {
 | |
|     return false;
 | |
|   }
 | |
|   setScrubbing() {}
 | |
|   fakeSourceset() {
 | |
|     this.el_.src = this.options_.sourceset;
 | |
|     this.el_.setAttribute('src', this.options_.sourceset);
 | |
|     super.triggerSourceset(this.options_.sourceset);
 | |
|   }
 | |
|   src(src) {
 | |
|     if (typeof src !== 'undefined' && this.options_ && this.options_.sourceset) {
 | |
|       this.fakeSourceset();
 | |
|     }
 | |
|     return 'movie.mp4';
 | |
|   }
 | |
|   addSourceElement() {}
 | |
|   removeSourceElement() {}
 | |
|   load() {
 | |
|   }
 | |
|   currentSrc() {
 | |
|     return 'movie.mp4';
 | |
|   }
 | |
|   volume() {
 | |
|     return this.volume_ || 0;
 | |
|   }
 | |
|   muted() {
 | |
|     return false;
 | |
|   }
 | |
|   defaultMuted() {
 | |
|     return false;
 | |
|   }
 | |
|   autoplay() {
 | |
|     return this.options_.autoplay || false;
 | |
|   }
 | |
|   pause() {
 | |
|     return false;
 | |
|   }
 | |
|   paused() {
 | |
|     return true;
 | |
|   }
 | |
|   loop() {
 | |
|     return false;
 | |
|   }
 | |
|   play() {
 | |
|     this.trigger('play');
 | |
|   }
 | |
|   supportsFullScreen() {
 | |
|     return false;
 | |
|   }
 | |
|   buffered() {
 | |
|     return {};
 | |
|   }
 | |
|   duration() {
 | |
|     return {};
 | |
|   }
 | |
|   networkState() {
 | |
|     return 0;
 | |
|   }
 | |
|   readyState() {
 | |
|     return 0;
 | |
|   }
 | |
|   controls() {
 | |
|     return false;
 | |
|   }
 | |
|   ended() {
 | |
|     return false;
 | |
|   }
 | |
|   crossOrigin() {
 | |
|     return null;
 | |
|   }
 | |
| 
 | |
|   // Support everything except for "video/unsupported-format"
 | |
|   static isSupported() {
 | |
|     return true;
 | |
|   }
 | |
|   static canPlayType(type) {
 | |
|     return (type !== 'video/unsupported-format' ? 'maybe' : '');
 | |
|   }
 | |
|   static canPlaySource(srcObj) {
 | |
|     return srcObj.type !== 'video/unsupported-format';
 | |
|   }
 | |
| }
 | |
| 
 | |
| Tech.registerTech('TechFaker', TechFaker);
 | |
| export default TechFaker;
 |