File tree Expand file tree Collapse file tree 3 files changed +41
-16
lines changed
Expand file tree Collapse file tree 3 files changed +41
-16
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ const offset = function(options) {
6969 options = options || { } ;
7070 const Player = this . constructor ;
7171
72- this . _offsetStart = options . start || 0 ;
73- this . _offsetEnd = options . end || 0 ;
72+ this . _offsetStart = parseFloat ( options . start || '0' ) ;
73+ this . _offsetEnd = parseFloat ( options . end || '0' ) ;
7474 this . _restartBeginning = options . restart_beginning || false ;
7575
7676 if ( ! Player . __super__ || ! Player . __super__ . __offsetInit ) {
@@ -92,10 +92,15 @@ const offset = function(options) {
9292 Player . prototype . currentTime = function ( seconds ) {
9393 if ( seconds !== undefined ) {
9494 return Player . __super__ . currentTime
95- . call ( this , seconds + this . _offsetStart ) - this . _offsetStart ;
95+ . call ( this , seconds + this . _offsetStart ) ;
9696 }
97- return Player . __super__ . currentTime
98- . apply ( this , arguments ) - this . _offsetStart ;
97+ const curr = Player . __super__ . currentTime
98+ . apply ( this ) ;
99+
100+ if ( curr > this . _offsetStart ) {
101+ return curr - this . _offsetStart ;
102+ }
103+ return 0 ;
99104 } ;
100105
101106 Player . prototype . remainingTime = function ( ) {
Original file line number Diff line number Diff line change 11module . exports = function ( config ) {
2- var detectBrowsers = {
3- enabled : false ,
4- usePhantomJS : false
5- } ;
6-
72 // On Travis CI, we can only run in Firefox and Chrome; so, enforce that.
83 if ( process . env . TRAVIS ) {
94 config . browsers = [ 'Firefox' , 'travisChrome' ] ;
105 }
116
12- // If no browsers are specified, we enable `karma-detect-browsers`
13- // this will detect all browsers that are available for testing
7+ // If no browsers are specified, assume is dev env and run ChromeHeadless
8+ // TODO: re-enable detect browsers when figure out how to make test work in
9+ // Safari
1410 if ( ! config . browsers . length ) {
15- detectBrowsers . enabled = true ;
11+ config . browsers = [ 'ChromeHeadless' ]
1612 }
1713
1814 config . set ( {
1915 basePath : '..' ,
20- frameworks : [ 'qunit' , 'detectBrowsers' ] ,
16+ frameworks : [ 'qunit' ] ,
2117 files : [
2218 'node_modules/video.js/dist/video-js.css' ,
23-
2419 'node_modules/es5-shim/es5-shim.js' ,
2520 'node_modules/sinon/pkg/sinon.js' ,
2621 'node_modules/video.js/dist/video.js' ,
@@ -32,7 +27,6 @@ module.exports = function(config) {
3227 flags : [ '--no-sandbox' ]
3328 }
3429 } ,
35- detectBrowsers : detectBrowsers ,
3630 reporters : [ 'dots' ] ,
3731 port : 9876 ,
3832 colors : true ,
Original file line number Diff line number Diff line change @@ -59,3 +59,29 @@ QUnit.test('registers itself with video.js', function(assert) {
5959 'the plugin alters video duration adjusting to start|end options'
6060 ) ;
6161} ) ;
62+
63+ QUnit . test ( 'configure start and end as as strings' , function ( assert ) {
64+ assert . expect ( 2 ) ;
65+
66+ assert . strictEqual (
67+ typeof Player . prototype . offset ,
68+ 'function' ,
69+ 'videojs-offset plugin was registered'
70+ ) ;
71+
72+ this . player . offset ( {
73+ start : '10.5' ,
74+ end : '300.5'
75+ } ) ;
76+
77+ // Tick the clock forward enough to trigger the player to be "ready".
78+ this . clock . tick ( 1 ) ;
79+
80+ this . player . currentTime ( 2 ) ;
81+
82+ assert . ok (
83+ this . player . currentTime ( ) === 2 ,
84+ 'the plugin alters seeking by applying the start correction'
85+ ) ;
86+ } ) ;
87+
You can’t perform that action at this time.
0 commit comments