define('application/managers/player', [
'rofl/lib/utils',
'antie/runtimecontext',
'application/managers/feature',
'application/constants'
], function (
Utils,
RuntimeContext,
FeatureManager,
Constants
) {
'use strict';
var device = RuntimeContext.getDevice(),
app = RuntimeContext.getCurrentApplication(),
config = RuntimeContext.getCurrentApplication().getConfiguration().player,
featureManager = FeatureManager.getInstance(),
_currentProgram = null,
_player = device.getMediaPlayer(),
_videoType,
_currentLivePlaybackPosition;
return {
/**
* Returns true if the device supports trickplay.
*
* @returns {boolean} - True if the device supports trickplay.
*/
isTrickplayEnabled: function () {
if (_videoType === 'live' && !featureManager.isLiveTrickplayEnabled()) {
return false;
}
return featureManager.isTrickplayEnabled();
},
/**
* Sets the current program.
*
* @param {Object} program - The program.
* @param {string} type - The program type.
*/
setProgram: function (program, type) {
_currentProgram = program;
_videoType = type;
},
/**
* Sets the live video playback position.
*
* @param {number} position - The playback position.
*/
setLivePlaybackPosition: function (position) {
_currentLivePlaybackPosition = position;
},
/**
* Returns the current program.
*
* @returns {Object|null} - The current program or null if not set.
*/
getProgram: function () {
return _currentProgram;
},
/**
* Returns the video type.
*
* @returns {Object} - The video type.
*/
getVideoType: function () {
return _videoType;
},
/**
* Returns the live playback position.
*
* @returns {number} - The live playback position.
*/
getLivePlaybackPosition: function () {
return _currentLivePlaybackPosition;
},
/**
* Returns the trickplay settings.
*
* @returns {Object|null} - The trickplay settings or null if the program is not set.
*/
getTrickplaySettings: function () {
var maxSeekValue = config.maxSeekValue,
startTime = _currentProgram.getStartTime(),
endTime = _currentProgram.getEndTime(),
canSeek = _currentProgram.canSeek();
if (!_currentProgram) {
return null;
}
return {
canSeek: canSeek,
maxSeekValue: maxSeekValue,
type: _videoType === Constants.RESTART_VIDEO_TYPE ? Constants.LIVE_VIDEO_TYPE : 'VOD',
startTime: startTime,
endTime: endTime,
currentLivePosition: _currentLivePlaybackPosition || app.getDate().getTime()
};
},
/**
* Returns the mediaplayer.
*
* @returns {Object} - The player.
*/
getPlayer: function () {
return _player;
},
/**
* Returns the maximum seek value.
*
* @returns {number} - The max seek value.
*/
getMaxSeekValue: function () {
return config.maxSeekValue;
},
/**
* Returns the player's current time.
*
* @returns {number} - Player current time.
*/
getCurrentTime: function () {
return _player.getCurrentTime();
},
/**
* Returns the current program's end time.
*
* @returns {number} - Current program's end time.
*/
getEndTime: function () {
return _currentProgram.getEndTime();
}
};
});