diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_events_plugin_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_events_plugin_spec.js index 89ceb234be..b9688c01fe 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_events_plugin_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_events_plugin_spec.js @@ -32,18 +32,19 @@ }); }); - it('can emit "play_video" event when canEmitPlayVideoEvent returns true', function () { - spyOn(state.videoPlayer, 'canEmitPlayVideoEvent').andReturn(true); + it('can emit "play_video" event when emitPlayVideoEvent is true', function () { + state.videoEventsPlugin.emitPlayVideoEvent = true; state.el.trigger('play'); expect(Logger.log).toHaveBeenCalledWith('play_video', { id: 'id', code: 'html5', currentTime: 10 }); + expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeFalsy(); }); - it('can not emit "play_video" event when canEmitPlayVideoEvent returns false', function () { - spyOn(state.videoPlayer, 'canEmitPlayVideoEvent').andReturn(false); + it('can not emit "play_video" event when emitPlayVideoEvent is false', function () { + state.videoEventsPlugin.emitPlayVideoEvent = false; state.el.trigger('play'); expect(Logger.log).not.toHaveBeenCalled(); }); @@ -55,6 +56,7 @@ code: 'html5', currentTime: 10 }); + expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy(); }); it('can emit "speed_change_video" event', function () { @@ -86,6 +88,7 @@ code: 'html5', currentTime: 10 }); + expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy(); Logger.log.reset(); state.el.trigger('stop'); @@ -94,6 +97,7 @@ code: 'html5', currentTime: 10 }); + expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy(); }); it('can emit "skip_video" event', function () { diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js index 660a77b55f..922908b743 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js @@ -5,7 +5,7 @@ require( ['video/03_video_player.js'], function (VideoPlayer) { describe('VideoPlayer', function () { - var state, oldOTBD, Logger = window.Logger, YT = window.YT; + var state, oldOTBD; beforeEach(function () { oldOTBD = window.onTouchBasedDevice; @@ -333,46 +333,6 @@ function (VideoPlayer) { expect($.fn.trigger).toHaveBeenCalledWith('ended', {}); }); }); - - describe('Video Player', function () { - beforeEach(function () { - state = jasmine.initializePlayer(); - state.videoEl = $('video, iframe'); - spyOn(Logger, 'log'); - }); - - it('will set emitPlayVideoEvent to false after onPlay is called', function () { - expect(state.videoPlayer.emitPlayVideoEvent).toBeTruthy(); - state.videoPlayer.onPlay(); - expect(state.videoPlayer.emitPlayVideoEvent).toBeFalsy(); - }); - - it('will set emitPlayVideoEvent to correct value in different states', function () { - // Initially emitPlayVideoEvent should be set to true - expect(state.videoPlayer.emitPlayVideoEvent).toBeTruthy(); - - /** - * @param {Integer} playerState - New state of the video player. - * @param {Boolean} emitPlayVideoEvent - Expected value of emitPlayVideoEvent after - * video player goes into playerState. - */ - var verifyEmitPlayVideoEventValue = function (playerState, emitPlayVideoEvent) { - state.videoPlayer.onStateChange({ - data: playerState - }); - expect(state.videoPlayer.emitPlayVideoEvent).toBe(emitPlayVideoEvent); - }; - - verifyEmitPlayVideoEventValue(YT.PlayerState.BUFFERING, true); - verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false); - verifyEmitPlayVideoEventValue(YT.PlayerState.BUFFERING, false); - verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false); - verifyEmitPlayVideoEventValue(YT.PlayerState.PAUSED, true); - verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false); - verifyEmitPlayVideoEventValue(YT.PlayerState.ENDED, true); - verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false); - }); - }); }); describe('onSeek Youtube', function(){ diff --git a/common/lib/xmodule/xmodule/js/src/video/03_video_player.js b/common/lib/xmodule/xmodule/js/src/video/03_video_player.js index e2ccbaaf14..ea1e4e4755 100644 --- a/common/lib/xmodule/xmodule/js/src/video/03_video_player.js +++ b/common/lib/xmodule/xmodule/js/src/video/03_video_player.js @@ -51,8 +51,7 @@ function (HTML5Video, Resizer) { update: update, figureOutStartEndTime: figureOutStartEndTime, figureOutStartingTime: figureOutStartingTime, - updatePlayTime: updatePlayTime, - canEmitPlayVideoEvent: canEmitPlayVideoEvent + updatePlayTime: updatePlayTime }; VideoPlayer.prototype = methodsDict; @@ -129,8 +128,6 @@ function (HTML5Video, Resizer) { state.videoPlayer.PlayerState = HTML5Video.PlayerState; } - state.videoPlayer.emitPlayVideoEvent = true; - state.videoPlayer.currentTime = 0; state.videoPlayer.goToStartTime = true; @@ -201,14 +198,6 @@ function (HTML5Video, Resizer) { } } - function canEmitPlayVideoEvent() { - if (this.videoPlayer.emitPlayVideoEvent) { - this.videoPlayer.emitPlayVideoEvent = false; - return true; - } - return false; - } - function _updateVcrAndRegion(state, isYoutube) { var update = function (state) { var duration = state.videoPlayer.duration(), @@ -731,7 +720,6 @@ function (HTML5Video, Resizer) { case this.videoPlayer.PlayerState.PAUSED: this.el.addClass('is-paused'); this.videoPlayer.onPause(); - this.videoPlayer.emitPlayVideoEvent = true; break; case this.videoPlayer.PlayerState.BUFFERING: this.el.addClass('is-buffered'); @@ -740,7 +728,6 @@ function (HTML5Video, Resizer) { case this.videoPlayer.PlayerState.ENDED: this.el.addClass('is-ended'); this.videoPlayer.onEnded(); - this.videoPlayer.emitPlayVideoEvent = true; break; case this.videoPlayer.PlayerState.CUED: this.el.addClass('is-cued'); diff --git a/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js b/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js index bc9182cd48..fa6efcae22 100644 --- a/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js +++ b/common/lib/xmodule/xmodule/js/src/video/09_events_plugin.js @@ -50,6 +50,7 @@ define('video/09_events_plugin.js', [], function() { 'destroy': this.destroy }; this.bindHandlers(); + this.emitPlayVideoEvent = true; }, bindHandlers: function() { @@ -61,17 +62,20 @@ define('video/09_events_plugin.js', [], function() { }, onPlay: function () { - if (this.state.videoPlayer.canEmitPlayVideoEvent()) { + if (this.emitPlayVideoEvent) { this.log('play_video', {currentTime: this.getCurrentTime()}); + this.emitPlayVideoEvent = false; } }, onPause: function () { this.log('pause_video', {currentTime: this.getCurrentTime()}); + this.emitPlayVideoEvent = true; }, onEnded: function () { this.log('stop_video', {currentTime: this.getCurrentTime()}); + this.emitPlayVideoEvent = true; }, onSkip: function (event, doNotShowAgain) {