bigscreen-player
Advanced tools
Comparing version 3.0.0 to 3.1.0
{ | ||
"name": "bigscreen-player", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Simplified media playback for bigscreen devices.", | ||
@@ -5,0 +5,0 @@ "main": "script/bigscreenplayer.js", |
@@ -26,2 +26,3 @@ require( | ||
var mockPluginsInterface; | ||
var mockDynamicWindowUtils; | ||
var mockAudioElement = document.createElement('audio'); | ||
@@ -56,2 +57,3 @@ var mockVideoElement = document.createElement('video'); | ||
}; | ||
mockDynamicWindowUtils = jasmine.createSpyObj('mockDynamicWindowUtils', ['autoResumeAtStartOfRange']); | ||
@@ -129,3 +131,4 @@ spyOn(mockVideoElement, 'addEventListener'); | ||
'dashjs': mockDashjs, | ||
'bigscreenplayer/plugins': mockPlugins | ||
'bigscreenplayer/plugins': mockPlugins, | ||
'bigscreenplayer/dynamicwindowutils': mockDynamicWindowUtils | ||
}); | ||
@@ -679,4 +682,5 @@ | ||
beforeEach(function () { | ||
setUpMSE(0, WindowTypes.SLIDING, MediaKinds.VIDEO); | ||
setUpMSE(0, WindowTypes.SLIDING, MediaKinds.VIDEO, 100, 1000); | ||
mseStrategy.load(null, 0); | ||
mockDynamicWindowUtils.autoResumeAtStartOfRange.calls.reset(); | ||
}); | ||
@@ -701,2 +705,20 @@ | ||
}); | ||
it('should start autoresume timeout when paused', function () { | ||
mseStrategy.setCurrentTime(101); | ||
mseStrategy.pause(); | ||
expect(mockDynamicWindowUtils.autoResumeAtStartOfRange).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should not start autoresume timeout when paused and disableAutoResume is set', function () { | ||
var opts = { | ||
disableAutoResume: true | ||
}; | ||
mseStrategy.setCurrentTime(101); | ||
mseStrategy.pause(opts); | ||
expect(mockDynamicWindowUtils.autoResumeAtStartOfRange).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
@@ -703,0 +725,0 @@ }); |
define( | ||
'bigscreenplayer/dynamicwindowutils', [ | ||
'bigscreenplayer/models/livesupport', | ||
'bigscreenplayer/playbackstrategy/modifiers/mediaplayerbase' | ||
'bigscreenplayer/debugger/debugtool' | ||
], | ||
function (LiveSupport, MediaPlayerBase) { | ||
function (LiveSupport, DebugTool) { | ||
'use strict'; | ||
@@ -52,4 +52,5 @@ | ||
function autoResumeAtStartOfRange (currentTime, seekableRange, addEventCallback, removeEventCallback, resume) { | ||
function autoResumeAtStartOfRange (currentTime, seekableRange, addEventCallback, removeEventCallback, checkNotPauseEvent, resume) { | ||
var resumeTimeOut = Math.max(0, currentTime - seekableRange.start - AUTO_RESUME_WINDOW_START_CUSHION_SECONDS); | ||
DebugTool.keyValue({key: 'autoresume', value: resumeTimeOut}); | ||
var autoResumeTimer = setTimeout(function () { | ||
@@ -63,3 +64,3 @@ removeEventCallback(undefined, detectIfUnpaused); | ||
function detectIfUnpaused (event) { | ||
if (event.state !== MediaPlayerBase.STATE.PAUSED) { | ||
if (checkNotPauseEvent(event)) { | ||
removeEventCallback(undefined, detectIfUnpaused); | ||
@@ -66,0 +67,0 @@ clearTimeout(autoResumeTimer); |
@@ -61,3 +61,9 @@ define( | ||
if (opts.disableAutoResume !== true) { | ||
DynamicWindowUtils.autoResumeAtStartOfRange(getCurrentTime(), getSeekableRange(), addEventCallback, removeEventCallback, resume); | ||
DynamicWindowUtils.autoResumeAtStartOfRange( | ||
getCurrentTime(), | ||
getSeekableRange(), | ||
addEventCallback, | ||
removeEventCallback, | ||
MediaPlayerBase.unpausedEventCheck, | ||
resume); | ||
} | ||
@@ -64,0 +70,0 @@ } |
@@ -68,3 +68,9 @@ define( | ||
mediaPlayer.pause(); | ||
DynamicWindowUtils.autoResumeAtStartOfRange(mediaPlayer.getCurrentTime(), mediaPlayer.getSeekableRange(), addEventCallback, removeEventCallback, resume); | ||
DynamicWindowUtils.autoResumeAtStartOfRange( | ||
mediaPlayer.getCurrentTime(), | ||
mediaPlayer.getSeekableRange(), | ||
addEventCallback, | ||
removeEventCallback, | ||
MediaPlayerBase.unpausedEventCheck, | ||
resume); | ||
} | ||
@@ -71,0 +77,0 @@ }, |
define( | ||
'bigscreenplayer/playbackstrategy/modifiers/mediaplayerbase', | ||
function () { | ||
return { | ||
var STATE = { | ||
EMPTY: 'EMPTY', // No source set | ||
STOPPED: 'STOPPED', // Source set but no playback | ||
BUFFERING: 'BUFFERING', // Not enough data to play, waiting to download more | ||
PLAYING: 'PLAYING', // Media is playing | ||
PAUSED: 'PAUSED', // Media is paused | ||
COMPLETE: 'COMPLETE', // Media has reached its end point | ||
ERROR: 'ERROR' // An error occurred | ||
}; | ||
STATE: { | ||
EMPTY: 'EMPTY', // No source set | ||
STOPPED: 'STOPPED', // Source set but no playback | ||
BUFFERING: 'BUFFERING', // Not enough data to play, waiting to download more | ||
PLAYING: 'PLAYING', // Media is playing | ||
PAUSED: 'PAUSED', // Media is paused | ||
COMPLETE: 'COMPLETE', // Media has reached its end point | ||
ERROR: 'ERROR' // An error occurred | ||
}, | ||
var EVENT = { | ||
STOPPED: 'stopped', // Event fired when playback is stopped | ||
BUFFERING: 'buffering', // Event fired when playback has to suspend due to buffering | ||
PLAYING: 'playing', // Event fired when starting (or resuming) playing of the media | ||
PAUSED: 'paused', // Event fired when media playback pauses | ||
COMPLETE: 'complete', // Event fired when media playback has reached the end of the media | ||
ERROR: 'error', // Event fired when an error condition occurs | ||
STATUS: 'status', // Event fired regularly during play | ||
SENTINEL_ENTER_BUFFERING: 'sentinel-enter-buffering', // Event fired when a sentinel has to act because the device has started buffering but not reported it | ||
SENTINEL_EXIT_BUFFERING: 'sentinel-exit-buffering', // Event fired when a sentinel has to act because the device has finished buffering but not reported it | ||
SENTINEL_PAUSE: 'sentinel-pause', // Event fired when a sentinel has to act because the device has failed to pause when expected | ||
SENTINEL_PLAY: 'sentinel-play', // Event fired when a sentinel has to act because the device has failed to play when expected | ||
SENTINEL_SEEK: 'sentinel-seek', // Event fired when a sentinel has to act because the device has failed to seek to the correct location | ||
SENTINEL_COMPLETE: 'sentinel-complete', // Event fired when a sentinel has to act because the device has completed the media but not reported it | ||
SENTINEL_PAUSE_FAILURE: 'sentinel-pause-failure', // Event fired when the pause sentinel has failed twice, so it is giving up | ||
SENTINEL_SEEK_FAILURE: 'sentinel-seek-failure', // Event fired when the seek sentinel has failed twice, so it is giving up | ||
SEEK_ATTEMPTED: 'seek-attempted', // Event fired when a device using a seekfinishedemitevent modifier sets the source | ||
SEEK_FINISHED: 'seek-finished' // Event fired when a device using a seekfinishedemitevent modifier has seeked successfully | ||
}; | ||
EVENT: { | ||
STOPPED: 'stopped', // Event fired when playback is stopped | ||
BUFFERING: 'buffering', // Event fired when playback has to suspend due to buffering | ||
PLAYING: 'playing', // Event fired when starting (or resuming) playing of the media | ||
PAUSED: 'paused', // Event fired when media playback pauses | ||
COMPLETE: 'complete', // Event fired when media playback has reached the end of the media | ||
ERROR: 'error', // Event fired when an error condition occurs | ||
STATUS: 'status', // Event fired regularly during play | ||
SENTINEL_ENTER_BUFFERING: 'sentinel-enter-buffering', // Event fired when a sentinel has to act because the device has started buffering but not reported it | ||
SENTINEL_EXIT_BUFFERING: 'sentinel-exit-buffering', // Event fired when a sentinel has to act because the device has finished buffering but not reported it | ||
SENTINEL_PAUSE: 'sentinel-pause', // Event fired when a sentinel has to act because the device has failed to pause when expected | ||
SENTINEL_PLAY: 'sentinel-play', // Event fired when a sentinel has to act because the device has failed to play when expected | ||
SENTINEL_SEEK: 'sentinel-seek', // Event fired when a sentinel has to act because the device has failed to seek to the correct location | ||
SENTINEL_COMPLETE: 'sentinel-complete', // Event fired when a sentinel has to act because the device has completed the media but not reported it | ||
SENTINEL_PAUSE_FAILURE: 'sentinel-pause-failure', // Event fired when the pause sentinel has failed twice, so it is giving up | ||
SENTINEL_SEEK_FAILURE: 'sentinel-seek-failure', // Event fired when the seek sentinel has failed twice, so it is giving up | ||
SEEK_ATTEMPTED: 'seek-attempted', // Event fired when a device using a seekfinishedemitevent modifier sets the source | ||
SEEK_FINISHED: 'seek-finished' // Event fired when a device using a seekfinishedemitevent modifier has seeked successfully | ||
}, | ||
var TYPE = { | ||
VIDEO: 'video', | ||
AUDIO: 'audio', | ||
LIVE_VIDEO: 'live-video', | ||
LIVE_AUDIO: 'live-audio' | ||
}; | ||
TYPE: { | ||
VIDEO: 'video', | ||
AUDIO: 'audio', | ||
LIVE_VIDEO: 'live-video', | ||
LIVE_AUDIO: 'live-audio' | ||
function unpausedEventCheck (event) { | ||
if (event && event.state) { | ||
return event.state !== STATE.PAUSED; | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
return { | ||
STATE: STATE, | ||
EVENT: EVENT, | ||
TYPE: TYPE, | ||
unpausedEventCheck: unpausedEventCheck | ||
}; | ||
} | ||
); |
@@ -10,2 +10,3 @@ define('bigscreenplayer/playbackstrategy/msestrategy', | ||
'bigscreenplayer/models/livesupport', | ||
'bigscreenplayer/dynamicwindowutils', | ||
@@ -15,3 +16,3 @@ // static imports | ||
], | ||
function (MediaState, WindowTypes, DebugTool, MediaKinds, Plugins, ManifestModifier, LiveSupport) { | ||
function (MediaState, WindowTypes, DebugTool, MediaKinds, Plugins, ManifestModifier, LiveSupport, DynamicWindowUtils) { | ||
var MSEStrategy = function (mediaSources, windowType, mediaKind, playbackElement, isUHD, device) { | ||
@@ -21,3 +22,3 @@ var mediaPlayer; | ||
var eventCallback; | ||
var eventCallbacks = []; | ||
var errorCallback; | ||
@@ -195,4 +196,4 @@ var timeUpdateCallback; | ||
function publishMediaState (mediaState) { | ||
if (eventCallback) { | ||
eventCallback(mediaState); | ||
for (var index = 0; index < eventCallbacks.length; index++) { | ||
eventCallbacks[index](mediaState); | ||
} | ||
@@ -331,6 +332,13 @@ } | ||
addEventCallback: function (thisArg, newCallback) { | ||
eventCallback = function (event) { | ||
var eventCallback = function (event) { | ||
newCallback.call(thisArg, event); | ||
}; | ||
eventCallbacks.push(eventCallback); | ||
}, | ||
removeEventCallback: function (callback) { | ||
var index = eventCallbacks.indexOf(callback); | ||
if (index !== -1) { | ||
eventCallbacks.splice(index, 1); | ||
} | ||
}, | ||
addErrorCallback: function (thisArg, newErrorCallback) { | ||
@@ -381,3 +389,3 @@ errorCallback = function (event) { | ||
mediaElement = undefined; | ||
eventCallback = undefined; | ||
eventCallbacks = undefined; | ||
errorCallback = undefined; | ||
@@ -399,4 +407,16 @@ timeUpdateCallback = undefined; | ||
isPaused: isPaused, | ||
pause: function () { | ||
pause: function (opts) { | ||
mediaPlayer.pause(); | ||
opts = opts || {}; | ||
if (opts.disableAutoResume !== true && windowType === WindowTypes.SLIDING) { | ||
DynamicWindowUtils.autoResumeAtStartOfRange( | ||
getCurrentTime(), | ||
getSeekableRange(), | ||
this.addEventCallback, | ||
this.removeEventCallback, | ||
function (event) { | ||
return event !== MediaState.PAUSED; | ||
}, | ||
mediaPlayer.play); | ||
} | ||
}, | ||
@@ -403,0 +423,0 @@ play: function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7828262
75542