From 60641b005f5dc2eb17f9f3d5fda6fc444e35db1a Mon Sep 17 00:00:00 2001 From: yameen Date: Tue, 14 Jun 2016 13:23:46 +0100 Subject: [PATCH] TVPE-239 changes to have a cushion on window start for auto resume --- .../devices/mediaplayer/live/restartable.js | 41 +++++++++++-------- .../devices/mediaplayer/live/seekable.js | 18 ++++---- .../devices/mediaplayer/live/restartable.js | 4 +- .../devices/mediaplayer/live/seekable.js | 3 +- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/static/script-tests/tests/devices/mediaplayer/live/restartable.js b/static/script-tests/tests/devices/mediaplayer/live/restartable.js index 241e3939..2a94da6d 100644 --- a/static/script-tests/tests/devices/mediaplayer/live/restartable.js +++ b/static/script-tests/tests/devices/mediaplayer/live/restartable.js @@ -223,8 +223,8 @@ }, config); }; - this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenBeginPlaybackFromThenPausedAndStartOfRangeIsReached = function (queue) { - expectAsserts(1); + this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenBeginPlaybackFromThenPausedAndStartOfRangeIsApproached = function (queue) { + expectAsserts(2); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/restartable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); var livePlayer = device.getLivePlayer(); @@ -237,7 +237,11 @@ var clock = sinon.useFakeTimers(); livePlayer.beginPlaybackFrom(30); livePlayer.pause(); - clock.tick(30 * 1000); + clock.tick(21 * 1000); + + assert(livePlayer._mediaPlayer.resume.notCalled); + + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); @@ -245,8 +249,8 @@ }, config); }; - this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenBeginPlaybackThenPausedAndStartOfRangeIsReached = function (queue) { - expectAsserts(1); + this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenBeginPlaybackThenPausedAndStartOfRangeIsApproached = function (queue) { + expectAsserts(2); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/restartable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); var livePlayer = device.getLivePlayer(); @@ -262,15 +266,20 @@ livePlayer.beginPlayback(); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); livePlayer.pause(); - clock.tick(30 * 1000); + clock.tick(21 * 1000); + + assert(livePlayer._mediaPlayer.resume.notCalled); + + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); clock.restore(); + }, config); }; - this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenPausedMultipleTimesAndStartOfRangeIsReached = function (queue) { + this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeWhenPausedMultipleTimesAndStartOfRangeIsApproached = function (queue) { expectAsserts(1); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/restartable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); @@ -285,10 +294,10 @@ var clock = sinon.useFakeTimers(); livePlayer.beginPlaybackFrom(30); livePlayer.pause(); - clock.tick(15 * 1000); + clock.tick(21 * 1000); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); livePlayer.pause(); - clock.tick(15 * 1000); + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); @@ -296,7 +305,7 @@ }, config); }; - this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeCancelledWhenPausedAndResumedBeforeStartOfRangeIsReached = function (queue) { + this.LivePlayerSupportLevelRestartableTest.prototype.testAutoResumeCancelledWhenPausedAndResumedBeforeStartOfRangeIsApproached = function (queue) { expectAsserts(1); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/restartable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); @@ -313,7 +322,7 @@ livePlayer.pause(); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); - clock.tick(30 * 1000); + clock.tick(22 * 1000); assert(livePlayer._mediaPlayer.resume.notCalled); @@ -392,7 +401,7 @@ livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.PAUSED); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.SENTINEL_PAUSE); - clock.tick(30 * 1000); + clock.tick(22 * 1000); assert(livePlayer._mediaPlayer.resume.called); @@ -419,14 +428,14 @@ livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.BUFFERING); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.BUFFERING); - clock.tick(10 * 1000); + clock.tick(21 * 1000); livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.PLAYING); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); livePlayer.pause(); - clock.tick(20 * 1000); + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); @@ -455,14 +464,14 @@ livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.BUFFERING); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.BUFFERING); - clock.tick(10 * 1000); + clock.tick(21 * 1000); livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.PLAYING); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); livePlayer.pause(); - clock.tick(20 * 1000); + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); diff --git a/static/script-tests/tests/devices/mediaplayer/live/seekable.js b/static/script-tests/tests/devices/mediaplayer/live/seekable.js index c7c4642d..262c8500 100644 --- a/static/script-tests/tests/devices/mediaplayer/live/seekable.js +++ b/static/script-tests/tests/devices/mediaplayer/live/seekable.js @@ -299,8 +299,8 @@ }, config); }; - this.LivePlayerSupportLevelSeekableTest.prototype.testAutoResumeWhenPausedAndStartOfRangeIsReached = function (queue) { - expectAsserts(1); + this.LivePlayerSupportLevelSeekableTest.prototype.testAutoResumeWhenPausedAndStartOfRangeIsApproached = function (queue) { + expectAsserts(2); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/seekable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); var livePlayer = device.getLivePlayer(); @@ -318,7 +318,11 @@ var clock = sinon.useFakeTimers(); livePlayer.pause(); - clock.tick(30 * 1000); + clock.tick(21 * 1000); + + assert(livePlayer._mediaPlayer.resume.notCalled); + + clock.tick(1 * 1000); assert(livePlayer._mediaPlayer.resume.called); @@ -345,7 +349,7 @@ var clock = sinon.useFakeTimers(); livePlayer.pause({disableAutoResume: true}); - clock.tick(30 * 1000); + clock.tick(22 * 1000); assert(livePlayer._mediaPlayer.resume.notCalled); @@ -354,7 +358,7 @@ }; - this.LivePlayerSupportLevelSeekableTest.prototype.testAutoResumeCancelledWhenPausedAndResumedBeforeStartOfRangeIsReached = function (queue) { + this.LivePlayerSupportLevelSeekableTest.prototype.testAutoResumeCancelledWhenPausedAndResumedBeforeStartOfRangeIsApproached = function (queue) { expectAsserts(1); queuedApplicationInit(queue, 'lib/mockapplication', ['antie/devices/mediaplayer/mediaplayer', 'antie/devices/device', 'antie/devices/mediaplayer/live/seekable'], function (application, MediaPlayer, Device) { var device = new Device(antie.framework.deviceConfiguration); @@ -377,7 +381,7 @@ livePlayer.pause(); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.PLAYING); - clock.tick(30 * 1000); + clock.tick(22 * 1000); assert(livePlayer._mediaPlayer.resume.notCalled); @@ -409,7 +413,7 @@ livePlayer._mediaPlayer.getState.returns(MediaPlayer.STATE.PAUSED); livePlayer._mediaPlayer._emitEvent(MediaPlayer.EVENT.SENTINEL_PAUSE); - clock.tick(30 * 1000); + clock.tick(22 * 1000); assert(livePlayer._mediaPlayer.resume.called); diff --git a/static/script/devices/mediaplayer/live/restartable.js b/static/script/devices/mediaplayer/live/restartable.js index 366ec27e..26c88faa 100644 --- a/static/script/devices/mediaplayer/live/restartable.js +++ b/static/script/devices/mediaplayer/live/restartable.js @@ -35,6 +35,7 @@ define( ], function (Class, RuntimeContext, Device, MediaPlayer) { 'use strict'; + var AUTO_RESUME_WINDOW_START_CUSHION_MILLISECONDS = 8000; /** * Live player for devices that support restarting while playing live streams, but cannot seek within them. @@ -153,12 +154,13 @@ define( _autoResumeAtStartOfRange: function () { var self = this; if (this._millisecondsUntilStartOfWindow !== null) { + var resumeTimeOut = Math.max(0, this._millisecondsUntilStartOfWindow - AUTO_RESUME_WINDOW_START_CUSHION_MILLISECONDS); var pauseStarted = new Date().getTime(); var autoResumeTimer = setTimeout(function () { self.removeEventCallback(self, detectIfUnpaused); self._millisecondsUntilStartOfWindow = 0; self.resume(); - }, self._millisecondsUntilStartOfWindow); + }, resumeTimeOut); this.addEventCallback(this, detectIfUnpaused); } diff --git a/static/script/devices/mediaplayer/live/seekable.js b/static/script/devices/mediaplayer/live/seekable.js index 16cfce16..75895065 100644 --- a/static/script/devices/mediaplayer/live/seekable.js +++ b/static/script/devices/mediaplayer/live/seekable.js @@ -35,6 +35,7 @@ define( ], function (Class, RuntimeContext, Device, MediaPlayer) { 'use strict'; + var AUTO_RESUME_WINDOW_START_CUSHION_SECONDS = 8; /** * Live player for devices that have full support for playing and seeking live streams. @@ -134,7 +135,7 @@ define( _autoResumeAtStartOfRange: function () { var self = this; - var timeUntilStartOfWindow = Math.max(0, this._mediaPlayer.getCurrentTime() - this._mediaPlayer.getSeekableRange().start); + var timeUntilStartOfWindow = Math.max(0, this._mediaPlayer.getCurrentTime() - this._mediaPlayer.getSeekableRange().start - AUTO_RESUME_WINDOW_START_CUSHION_SECONDS); var autoResumeTimer = setTimeout(function () { self.removeEventCallback(self, detectIfUnpaused);