Skip to content

Commit

Permalink
Merge pull request #368 from fmtvp/TVPE-239
Browse files Browse the repository at this point in the history
TVPE-239 changes to have a cushion on window start for auto resume
  • Loading branch information
Luke Preston authored Jun 14, 2016
2 parents 1d0837e + 60641b0 commit ad12e2c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
41 changes: 25 additions & 16 deletions static/script-tests/tests/devices/mediaplayer/live/restartable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -237,16 +237,20 @@
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);

clock.restore();
}, 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();
Expand All @@ -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);
Expand All @@ -285,18 +294,18 @@
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);

clock.restore();
}, 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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
18 changes: 11 additions & 7 deletions static/script-tests/tests/devices/mediaplayer/live/seekable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion static/script/devices/mediaplayer/live/restartable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion static/script/devices/mediaplayer/live/seekable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ad12e2c

Please sign in to comment.