| 
									
										
										
										
											2013-01-25 17:36:40 -08:00
										 |  |  | // Fake a media playback tech controller so that player tests
 | 
					
						
							| 
									
										
										
										
											2020-12-22 20:10:53 +01:00
										 |  |  | // can run without HTML5 which PhantomJS does not support.
 | 
					
						
							| 
									
										
										
										
											2015-05-03 16:12:38 -07:00
										 |  |  | import Tech from '../../../src/js/tech/tech.js'; | 
					
						
							| 
									
										
										
										
											2022-05-23 16:23:13 -04:00
										 |  |  | import {createTimeRanges} from '../../../src/js/utils/time.js'; | 
					
						
							| 
									
										
										
										
											2013-01-25 17:36:40 -08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-09-28 14:58:15 -04:00
										 |  |  |  * @class | 
					
						
							| 
									
										
										
										
											2013-01-25 17:36:40 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-05-03 16:12:38 -07:00
										 |  |  | class TechFaker extends Tech { | 
					
						
							| 
									
										
										
										
											2013-01-17 20:33:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   constructor(options, handleReady) { | 
					
						
							| 
									
										
										
										
											2015-05-06 14:01:52 -04:00
										 |  |  |     super(options, handleReady); | 
					
						
							| 
									
										
										
										
											2018-10-25 18:56:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  |     this.featuresPlaybackRate = true; | 
					
						
							|  |  |  |     this.defaultPlaybackRate_ = 1; | 
					
						
							|  |  |  |     this.playbackRate_ = 1; | 
					
						
							|  |  |  |     this.currentTime_ = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 18:56:56 -04:00
										 |  |  |     if (this.options_ && this.options_.sourceset) { | 
					
						
							|  |  |  |       this.fakeSourceset(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-02 14:35:45 -05:00
										 |  |  |     if (!options || options.autoReady !== false) { | 
					
						
							|  |  |  |       this.triggerReady(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-09 13:43:35 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   createEl() { | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |     const el = super.createEl('div', { | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  |       className: 'vjs-tech' | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return el; | 
					
						
							| 
									
										
										
										
											2013-04-04 09:55:27 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-01-17 20:33:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  |   // fake a poster attribute to mimic the video element
 | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   poster() { | 
					
						
							|  |  |  |     return this.el().poster; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   setPoster(val) { | 
					
						
							|  |  |  |     this.el().poster = val; | 
					
						
							| 
									
										
										
										
											2018-03-07 20:31:50 +01:00
										 |  |  |     this.trigger('posterchange'); | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-06 14:01:52 -04:00
										 |  |  |   setControls(val) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  |   setVolume(value) { | 
					
						
							|  |  |  |     this.volume_ = value; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
											  
											
												feat: middleware (#3788)
Add middleware support. Middleware can function as go-between between the player and the tech. For example, it can modify the duration that the tech returns to the player. In addition, middleware allow for supporting custom video sources and types.
Currently, middleware can only intercept timeline methods like duration, currentTime, and setCurrentTime.
For example,
```js
videojs.use('video/foo', {
  setSource(src, next) {
    next(null, {
      src: 'http://example.com/video.mp4',
      type: 'video/mp4'
    });
  }
});
```
Will allow you to set a source with type `video/foo` which will play back `video.mp4`.
This makes setting the source asynchronous, which aligns it with the spec a bit more. Methods like play can still be called synchronously on the player after setting the source and the player will play once the source has loaded.
`sourceOrder` option was removed as well and it will now always use source ordering.
BREAKING CHANGE: setting the source is now asynchronous. `sourceOrder` option removed and made the default.
											
										 
											2017-01-19 17:29:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-31 17:15:56 -05:00
										 |  |  |   setMuted() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-31 17:12:57 +02:00
										 |  |  |   setDefaultMuted() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-21 14:32:07 -04:00
										 |  |  |   setAutoplay(v) { | 
					
						
							|  |  |  |     if (!v) { | 
					
						
							|  |  |  |       this.options_.autoplay = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.options_.autoplay = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-12-14 11:24:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  |   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'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   currentTime() { | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  |     return this.currentTime_; | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 15:31:23 -05:00
										 |  |  |   seekable() { | 
					
						
							|  |  |  |     return createTimeRanges(0, 0); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   seeking() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-22 12:40:26 -04:00
										 |  |  |   setScrubbing() {} | 
					
						
							| 
									
										
										
										
											2018-10-25 18:56:56 -04:00
										 |  |  |   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(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |     return 'movie.mp4'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-10-09 12:16:04 -04:00
										 |  |  |   addSourceElement() {} | 
					
						
							|  |  |  |   removeSourceElement() {} | 
					
						
							| 
									
										
										
										
											2019-03-18 14:33:55 -04:00
										 |  |  |   load() { | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-03 12:50:55 -07:00
										 |  |  |   currentSrc() { | 
					
						
							|  |  |  |     return 'movie.mp4'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   volume() { | 
					
						
							| 
									
										
										
										
											2019-01-03 15:14:54 -05:00
										 |  |  |     return this.volume_ || 0; | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   } | 
					
						
							|  |  |  |   muted() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-05-31 17:12:57 +02:00
										 |  |  |   defaultMuted() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-12-14 11:24:48 -05:00
										 |  |  |   autoplay() { | 
					
						
							| 
									
										
										
										
											2018-06-21 14:32:07 -04:00
										 |  |  |     return this.options_.autoplay || false; | 
					
						
							| 
									
										
										
										
											2017-12-14 11:24:48 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   pause() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   paused() { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-01-30 11:30:42 -05:00
										 |  |  |   loop() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   play() { | 
					
						
							|  |  |  |     this.trigger('play'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   supportsFullScreen() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   buffered() { | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   duration() { | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   networkState() { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   readyState() { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   controls() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-08-29 17:02:56 -04:00
										 |  |  |   ended() { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-04-22 16:39:01 -04:00
										 |  |  |   crossOrigin() { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Support everything except for "video/unsupported-format"
 | 
					
						
							| 
									
										
										
										
											2016-08-03 15:27:03 -04:00
										 |  |  |   static isSupported() { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   static canPlayType(type) { | 
					
						
							|  |  |  |     return (type !== 'video/unsupported-format' ? 'maybe' : ''); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   static canPlaySource(srcObj) { | 
					
						
							|  |  |  |     return srcObj.type !== 'video/unsupported-format'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-14 13:08:32 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-25 21:43:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 15:53:14 -05:00
										 |  |  | Tech.registerTech('TechFaker', TechFaker); | 
					
						
							| 
									
										
										
										
											2015-05-03 16:12:38 -07:00
										 |  |  | export default TechFaker; |