|
var appli = null; |
|
var PAGENAME = location.pathname; |
|
|
|
function log(a, b, c) { |
|
if (opener && opener.log) opener.log(a, (isDefined(b) && isDefined(b.toSource) ? eval(b.toSource()) : b), c, PAGENAME); |
|
else if (parent && parent.log) parent.log(a, (isDefined(b) && isDefined(b.toSource) ? eval(b.toSource()) : b), c, PAGENAME); |
|
} |
|
|
|
function isDefined(testIt) { |
|
return (typeof (testIt) != "undefined" && testIt != null); |
|
} |
|
|
|
function getSource(obj) { |
|
if (opener && opener.getSource) return opener.getSource(obj); |
|
else if (parent && parent.getSource) return parent.getSource(obj); |
|
} |
|
|
|
function getClone(obj) { |
|
if (opener && opener.getClone) return opener.getClone(obj); |
|
else if (parent && parent.getClone) return parent.getClone(obj); |
|
} |
|
|
|
function init() { |
|
appli = new Player("appli"); |
|
appli._getCTN(); |
|
} |
|
|
|
function getFocus() {} |
|
|
|
function unload() { |
|
appli.isUnload = true; |
|
appli._stopPlayer(); |
|
appli.quit(null, null, true); |
|
} |
|
|
|
function quit() { |
|
if (appli) { |
|
appli.isUnload = true; |
|
appli.quit(); |
|
} |
|
} |
|
|
|
function PlayList(selfName) { |
|
this.selfName = selfName; |
|
this.DEBUG_ID = 2; |
|
this.list = new Array(); |
|
this.report = new Object(); |
|
this.index = -1; |
|
this.id = ""; |
|
} |
|
PlayList.prototype.init = function PlayList_init(playList, hashFct) { |
|
this.list = new Array(); |
|
this.hashFct = hashFct; |
|
for (var i = 0; i < playList.length; i++) { |
|
var media = new Media(this.selfName + ".list[" + this.list.length + "]", playList[i]); |
|
media.index = i; |
|
this.list.push(media); |
|
} |
|
this.setId(); |
|
this.index = -1; |
|
} |
|
PlayList.prototype.setId = function PlayList_setId() { |
|
this.id = ""; |
|
for (var i in this.list) { |
|
var media = this.list[i]; |
|
if (media.type == media.TYPE_ASSET) { |
|
if (media.target.assetId) { |
|
this.id += media.target.assetId; |
|
media.idRecovery = media.target.assetId; |
|
} |
|
} else if (media.id) { |
|
this.id += media.id; |
|
media.idRecovery = media.id; |
|
} else if (media.type == media.TYPE_HTTP || media.type == media.TYPE_RTSP) { |
|
var hash = this.hashFct(media.target); |
|
this.id += hash; |
|
media.idRecovery = hash; |
|
} else if (media.type == media.TYPE_ID) { |
|
if (media.target) { |
|
this.id += media.target; |
|
media.idRecovery = media.id; |
|
} |
|
} |
|
} |
|
} |
|
PlayList.prototype.getMedia = function PlayList_getMedia(offset) { |
|
var index = this.index + (typeof (offset) == "number" ? parseInt(offset, 10) : 0); |
|
return (index >= 0 && index < this.list.length ? this.list[index] : false); |
|
} |
|
PlayList.prototype.setIndexByOffset = function PlayList_setIndexByOffset(offset) { |
|
this.index = this.index + (typeof (offset) == "number" ? parseInt(offset, 10) : 0); |
|
} |
|
PlayList.prototype.getVideoToSave = function PlayList_getVideoToSave(offset) { |
|
var index = isDefined(offset) ? this.index + offset : this.index; |
|
for (var i = index; i >= 0; i--) { |
|
var media = this.list[i]; |
|
if (media.idRecovery && !media.onceOnly) { |
|
if (isDefined(media.oldPosition)) { |
|
media.oldPosition -= 8000; |
|
if (media.oldPosition < 0) media.oldPosition = 0; |
|
} else { |
|
media.oldPosition = null; |
|
} |
|
return media; |
|
} else return this.getVideoToSave((offset ? offset : 0) - 1); |
|
} |
|
return false; |
|
} |
|
PlayList.prototype.getMediaByRecoveryId = function PlayList_getMediaByRecoveryId(id) { |
|
for (var i = 0; i < this.list.length; i++) { |
|
if (this.list[i].idRecovery == id) return this.list[i]; |
|
} |
|
return false; |
|
} |
|
PlayList.prototype.next = function Playlist_next() {} |
|
PlayList.prototype.previous = function Playlist_previous() {} |
|
PlayList.prototype.getReport = function Playlist_getReport() { |
|
this.report.index = this.index; |
|
this.report.list = new Array(); |
|
this.report.date = new Date().getTime(); |
|
for (var i = 0; i < this.list.length; i++) { |
|
var media = this.list[i]; |
|
this.report.list[i] = {}; |
|
this.report.list[i].id = media.id; |
|
this.report.list[i].traces = new Array(); |
|
for (var j = 0; j < media.traces.length; j++) { |
|
var trace = media.traces[j]; |
|
if (trace[1] == "loading" || trace[1] == "playing" || trace[1] == "drmDetect" || trace[1] == "drmDecrypt" || trace[1] == "ED" || trace[1] == "error" || trace[1] == "confirmed" || trace[1] == "stopped" || trace[1] == "ended") this.report.list[i].traces.push(trace); |
|
} |
|
var inserts = media.getInserts(); |
|
if (inserts) { |
|
this.report.list[i].inserts = new Array(); |
|
for (var cptInsert = 0; cptInsert < inserts.length; cptInsert++) { |
|
this.report.list[i].inserts[cptInsert] = {}; |
|
var insert = inserts[cptInsert]; |
|
this.report.list[i].inserts[cptInsert].id = insert.id; |
|
this.report.list[i].inserts[cptInsert].traces = new Array(); |
|
for (var cptTrace = 0; cptTrace < insert.traces.length; cptTrace++) { |
|
var trace = insert.traces[cptTrace]; |
|
if (trace[1] == "loading" || trace[1] == "playing" || trace[1] == "drmDetect" || trace[1] == "drmDecrypt" || trace[1] == "ED" || trace[1] == "error" || trace[1] == "confirmed" || trace[1] == "stopped" || trace[1] == "ended") this.report.list[i].inserts[cptInsert].traces.push(trace); |
|
} |
|
} |
|
} |
|
} |
|
return this.report; |
|
} |
|
PlayList.prototype.toString = function Playlist_toString() { |
|
var str = "plLen=" + this.list.length; |
|
for (var m = 0; m < this.list.length; m++) { |
|
var media = this.list[m]; |
|
if (media) str += ":m" + (m + 1) + ";i" + media.nbInserts(); |
|
} |
|
return str + ""; |
|
} |
|
|
|
function Player(selfName) { |
|
this.selfName = selfName; |
|
this.DEBUG_ID = 2; |
|
this.PCR_DELAY = 600; |
|
this.gain = 0; |
|
this.playList = new PlayList(this.selfName + ".playList"); |
|
this.isUnload = false; |
|
this.screenForcedTime = null; |
|
this.screenForcedTimeout = null; |
|
this.launchDelayTimeout = null; |
|
this._checkingInterval = null; |
|
this._checkingTimeout = null; |
|
this._checkingTime = 2000; |
|
this._checkingRoutineOldPosition = -1; |
|
this._checkingRoutineMajorCpt = 0; |
|
this._checkingRoutineMajorMax = 5; |
|
this._checkingRoutineOldPacketErrors = 0; |
|
this._checkingRoutineMinorCpt = 0; |
|
this._checkingRoutineMinorMax = 5; |
|
this._checkingEDLastDone = new Date(); |
|
this._trackingTimeout = null; |
|
this.trackingPositions = [10000, 20000, 30000, 60000]; |
|
this._cookieMaxSavePls = 10; |
|
this.reprisePositionMini = 10000; |
|
this.infoBanner = { |
|
obj: false, |
|
callback: false, |
|
ACTIONS: new Object(), |
|
isVisible: function () { |
|
return false; |
|
} |
|
}; |
|
this.infoBannerLoaded = false; |
|
} |
|
Player.prototype.TYPE_HTTP = "HTTP"; |
|
Player.prototype.TYPE_RTSP = "RTSP"; |
|
Player.prototype.TIME_BEFORE_SUGGESTION = 80; |
|
Player.prototype.TIMER_TRICKMODES = 500; |
|
Player.prototype._getCTN = function Player__getCTN(times) { |
|
if (!times) times = 0; |
|
if (opener) { |
|
if (times < 10)!(this.CTN = opener.getInterface()) ? setTimeout(this.selfName + "._getCTN(" + (times + 1) + ")", 100) : this.init(); |
|
} else if (parent.location != document.location) { |
|
this.CTN = parent.getInterface(); |
|
this.init(); |
|
} else return false; |
|
} |
|
Player.prototype.init = function Player_init(cpt) { |
|
var partnerConf = this.CTN.getAppli(this.CTN.caller); |
|
this.playInserts = this.CTN.stb.system.getOption("ctn.player.inserts"); |
|
this.playInserts = (this.playInserts === false || this.playInserts === "false" ? false : true); |
|
var infoBanner = "infoBanner"; |
|
var skin = null; |
|
if (partnerConf.player) { |
|
if (isDefined(partnerConf.player.gain)) this.gain = partnerConf.player.gain; |
|
if (partnerConf.player.template) infoBanner = partnerConf.player.template; |
|
if (partnerConf.player.skin) skin = partnerConf.player.skin; |
|
} |
|
cpt = (!isDefined(cpt) ? 0 : cpt); |
|
if (!this.infoBannerLoaded) { |
|
if (cpt < 10) { |
|
if (cpt == 0) { |
|
this.params = this.CTN.appliStart(); |
|
this.partnerCallback = this.CTN.appliSetInterface({ |
|
obj: this, |
|
fct: "partnerInterface" |
|
}); |
|
if (this.params.skin) skin = this.params.skin; |
|
this.infoBannerInterface = this.CTN.appliLoad(infoBanner, { |
|
skin: skin, |
|
methods: this.params.methods |
|
}, { |
|
obj: this, |
|
fct: "playerInterface" |
|
}); |
|
} |
|
cpt++; |
|
setTimeout(this.selfName + ".init(" + cpt + ");", 500); |
|
} else { |
|
this.quit({ |
|
error: { |
|
internalError: "BI0", |
|
detail: "PB_chargement_infoBanner" |
|
} |
|
}); |
|
} |
|
return false; |
|
} |
|
this.reading = []; |
|
this.DVB_ORIGINAL_FORMAT = this.CTN.stb.audioVideo.getVideoARConversion(); |
|
this.DVB_ORIGINAL_GAIN_AUDIO = this.CTN.stb.audioVideo.getAudioGain(); |
|
this.CTN.stb.audioVideo.setAudioGain(0); |
|
this.CTN.tvSetStyle(); |
|
if ((this.params.playList && this.params.list && this.params.list.length) || (this.params.id_transaction || this.params.idTransaction)) { |
|
var plV2fromV1 = { |
|
report: false, |
|
playList: new Array() |
|
}; |
|
if (this.params.playList && this.params.list.length) { |
|
for (var i = 0; i < this.params.list.length; i++) { |
|
var itemToConvert = this.params.list[i]; |
|
var itemConverted = {}; |
|
itemConverted.id = Math.floor(Math.random() * 10000000); |
|
itemConverted.target = (itemToConvert.type == "rtsp" ? itemToConvert.idTransaction : itemToConvert.url); |
|
if (isDefined(itemToConvert.screen)) itemConverted.screen = itemToConvert.screen; |
|
if (isDefined(itemToConvert.screenTimeout)) itemConverted.screenTimeout = itemToConvert.screenTimeout; |
|
if (isDefined(itemToConvert.bitrate)) itemConverted.bitrate = itemToConvert.bitrate; |
|
if (isDefined(itemToConvert.name)) itemConverted.name = itemToConvert.name; |
|
if (isDefined(itemToConvert.desc)) itemConverted.desc = itemToConvert.desc; |
|
if (isDefined(itemToConvert.starttime)) itemConverted.startTime = itemToConvert.starttime; |
|
if (isDefined(itemToConvert.endtime)) itemConverted.endTime = itemToConvert.endtime; |
|
if (isDefined(itemToConvert.duration)) itemConverted.duration = itemToConvert.duration; |
|
itemConverted.infoBanner = (itemToConvert.type == "rtsp" ? true : false); |
|
itemConverted.trickMode = (itemToConvert.type == "rtsp" ? true : false); |
|
plV2fromV1.playList.push(itemConverted); |
|
} |
|
} else { |
|
plV2fromV1.playList.push({ |
|
target: (this.params.id_transaction || this.params.idTransaction) |
|
}); |
|
} |
|
this.params = plV2fromV1; |
|
} |
|
if ((this.params.report === true) || (this.params.report === "true")) this.report = true; |
|
this.CTN.KM.setHandler(document); |
|
this.infoBannerInterface.call(this.infoBannerInterface.CONST.INIT); |
|
this.infoBannerInterface.call("KEYMODE", this.CTN.KM.MODE_LIVE_NOZAP); |
|
var playVideo = this.loadPlaylist(); |
|
this._sendTrace({ |
|
name: "start", |
|
datas: { |
|
details: this.playList |
|
} |
|
}); |
|
if (playVideo) this.playNextVideo(); |
|
} |
|
Player.prototype.loadPlaylist = function Player_loadPlaylist() { |
|
if (this.params.target) { |
|
var target = this.params.target; |
|
this.params.playList = new Array({ |
|
target: target |
|
}); |
|
this.playList.init(this.params.playList, this.CTN.getHash); |
|
delete(this.params.target); |
|
} else if (this.params.playList) { |
|
this.playList.init(this.params.playList, this.CTN.getHash); |
|
if (!this.playList.list.length) { |
|
this.quit({ |
|
error: { |
|
internalError: "PV1", |
|
detail: "playList_vide" |
|
} |
|
}); |
|
return false; |
|
} |
|
} else { |
|
this.quit({ |
|
error: { |
|
internalError: "PV1", |
|
detail: "nothing_to_play" |
|
} |
|
}); |
|
return false; |
|
} |
|
var playlist = new Array(); |
|
for (var i = 0; i < this.playList.list.length; i++) { |
|
var item = new Object(); |
|
item.name = this.playList.list[i].name; |
|
item.subtitle = this.playList.list[i].subtitle; |
|
item.desc = this.playList.list[i].desc; |
|
item.image = this.playList.list[i].image; |
|
playlist.push(item); |
|
} |
|
this.infoBannerInterface.call("PLAYLIST", playlist); |
|
var isReprisePartner = false; |
|
if (isDefined(this.params.resumeIndex)) { |
|
isReprisePartner = true; |
|
var index = this.params.resumeIndex; |
|
if (index < this.playList.list.length && index > 0) this.playList.index = index - 1; |
|
} |
|
if (isDefined(this.params.resumePosition)) { |
|
isReprisePartner = true; |
|
var index = this.playList.index + 1; |
|
if (this.setReprise(this.playList.list[index].idRecovery, this.params.resumePosition)) return false; |
|
} |
|
if (this.playList.id && !isReprisePartner) { |
|
this.cookie = this.CTN.appliGetSetting(this.selfName + ".playListIds"); |
|
if (this.cookie) { |
|
var svgPls = this.cookie.split(";"); |
|
for (var i = 0; i < svgPls.length; i++) { |
|
var fields = svgPls[i].split("|"); |
|
if (fields[0] == this.playList.id) { |
|
if (this.setReprise(fields[1], parseInt(fields[2], 10))) return false; |
|
} |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
Player.prototype.setReprise = function Player_setReprise(id, time) { |
|
var media = this.playList.getMediaByRecoveryId(id); |
|
if (media) { |
|
var inserts = (this.playInserts ? media.getInserts(media.TIME_START) : false); |
|
for (var i in inserts) { |
|
inserts[i].ended = true; |
|
} |
|
this.playList.index = media.index; |
|
media.setReprisePosition(time); |
|
this.infoBannerInterface.call("RECOVERY"); |
|
return true; |
|
} |
|
return false; |
|
} |
|
Player.prototype.partnerInterface = function Player_partnerInterface(action, params) { |
|
switch (action) { |
|
case "REFRESH": |
|
this.infoBannerInterface.call("HIDE"); |
|
this.playList = new PlayList(this.selfName + ".playList"); |
|
this.params = params; |
|
if (this.loadPlaylist()) this.playNextVideo(); |
|
break; |
|
case "SET_METHOD": |
|
if (this.infoBannerInterface) this.infoBannerInterface.call(action, params); |
|
break; |
|
} |
|
} |
|
Player.prototype.playerInterface = function Player_playerInterface(action, params) { |
|
var media = this.getCurrentMedia(); |
|
var status = (this.player ? this.player.getStatus() : false); |
|
switch (action) { |
|
case "SEL_AUDIO": |
|
if (params && this.player) { |
|
this.playerUpdating = setTimeout(this.selfName + ".playerUpdating=false;", 3000); |
|
this.player.setAudio(params); |
|
media.componentsToRefresh = true; |
|
} |
|
break; |
|
case "SEL_SUBTITLE": |
|
if (params && this.player) { |
|
this.playerUpdating = setTimeout(this.selfName + ".playerUpdating=false;", 3000); |
|
this.player.setSubtitles((!params || params.pid == "0" ? false : params)); |
|
media.componentsToRefresh = true; |
|
} |
|
break; |
|
case "SEL_FORMAT": |
|
if (params && isDefined(params.id) && this.player) { |
|
if (typeof (params.id) != "number") return false; |
|
this.playerUpdating = setTimeout(this.selfName + ".playerUpdating=false;", 3000); |
|
this.CTN.stb.audioVideo.setVideoARConversion(params.id); |
|
media.componentsToRefresh = true; |
|
} |
|
break; |
|
case this.infoBannerInterface.CONST.INIT: |
|
this.infoBannerLoaded = true; |
|
break; |
|
case "STOP": |
|
case this.infoBannerInterface.CONST.CLOSE: |
|
var showSuggestion = false; |
|
var video = this.playList.getMedia(); |
|
if (video && (this.playList.index == this.playList.list.length - 1) && this.player) { |
|
var position = video.position; |
|
var duration = video.duration; |
|
if (position && duration && ((position / duration) >= (this.TIME_BEFORE_SUGGESTION / 100))) showSuggestion = true; |
|
} |
|
this._stopPlayer(); |
|
if (showSuggestion && this.params.suggestions && (this.params.suggestions.length > 0) && this.partnerCallback) { |
|
video.ended = true; |
|
this.infoBannerInterface.call("SUGGESTIONS", this.params.suggestions); |
|
} else { |
|
this.quit(); |
|
} |
|
break; |
|
case "SHOW_PLAYLIST": |
|
this._sendTrace({ |
|
name: "pause", |
|
"status": status |
|
}); |
|
this.player.setPlaySpeed(0); |
|
break; |
|
case "SEL_PLAYLIST": |
|
var position = this.player.getCurrentPosition(); |
|
if (!(position > media.duration)) media.setReprisePosition(position); |
|
this._stopPlayer(); |
|
this.reading.pop(); |
|
this.playList.index = params; |
|
media = this.playList.getMedia(); |
|
this.infoBannerInterface.call("HIDE"); |
|
this.playMedia(media); |
|
break; |
|
case "SEL_SUGGESTION": |
|
this.partnerCallback.call("SUGGESTION", this.params.suggestions[params]); |
|
break; |
|
case "RESIZE": |
|
this.changePosition(params); |
|
break; |
|
case "FULLSCREEN": |
|
if (this.player.getCurrentPlaySpeed() != 1) { |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 1, |
|
show: true |
|
}); |
|
this._sendTrace({ |
|
name: "play", |
|
"status": status |
|
}); |
|
this.player.setPlaySpeed(1); |
|
} |
|
break; |
|
case "GOTO": |
|
var status = this.player.getStatus(); |
|
if (this.player && (status.state == this.player.STATUS_STATE_PLAYING || status.state == this.player.STATUS_STATE_PAUSED)) { |
|
this.setPosition(params); |
|
} |
|
break; |
|
case "SEL_CHAPTER": |
|
var status = this.player.getStatus(); |
|
this.player.setPlaySpeed(1); |
|
this.setPosition(params); |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 1 |
|
}); |
|
this.infoBannerInterface.call("HIDE"); |
|
break; |
|
case "SEL_METHOD": |
|
if (this.partnerCallback) this.partnerCallback.call(action, params); |
|
break; |
|
case "RECOVERY": |
|
media = this.playList.getMedia(); |
|
if (!params) { |
|
media.setReprisePosition(0); |
|
this.playList.index = 0; |
|
media = this.playList.getMedia(); |
|
} |
|
this.playMedia(media); |
|
break; |
|
case "PLAY": |
|
if (media && media.trickMode) this.playPause(); |
|
break; |
|
case "REWIND": |
|
case "FORWARD": |
|
if (media && media.trickMode) this.videoChangeSpeed(action); |
|
break; |
|
} |
|
} |
|
Player.prototype.changePosition = function Player_changePosition(position) { |
|
var newPosition = { |
|
width: 1280, |
|
height: 720, |
|
top: 0, |
|
left: 0 |
|
}; |
|
if (position.width < 1280) newPosition.width = position.width + 20; |
|
if (position.height < 720) newPosition.height = position.height + 15; |
|
if (position.top > 0) newPosition.top = position.top - 10; |
|
if (position.left > 0) newPosition.left = position.left - 5; |
|
this.CTN.tvSetStyle(newPosition); |
|
} |
|
Player.prototype._unblockTrickmodes = function Player__unblockTrickmodes() { |
|
if (this.timeoutTrickmode) clearTimeout(this.timeoutTrickmode); |
|
this.trickmodesBlocked = false; |
|
} |
|
Player.prototype.videoChangeSpeed = function Player_videoChangeSpeed(keyName) { |
|
if (!this.player || this.trickmodesBlocked) return false; |
|
this.trickmodesBlocked = true; |
|
this.timeoutTrickmode = setTimeout(this.selfName + "._unblockTrickmodes();", this.TIMER_TRICKMODES); |
|
var media = this.getCurrentMedia(); |
|
var ps = this.player.getAvailablePlaySpeedsList(); |
|
if (!ps.length) { |
|
return true; |
|
} |
|
var cs = this.player.getCurrentPlaySpeed(); |
|
var speed = cs; |
|
for (var i = 0; i < ps.length; i++) { |
|
if (ps[i] == cs) { |
|
if (keyName == "FORWARD" && i < ps.length - 1) { |
|
speed = ps[i + 1]; |
|
if (!speed) { |
|
if (ps[i + 2]) speed = ps[i + 2]; |
|
else return false; |
|
} else if (speed == 1) { |
|
if (ps[i + 2]) speed = ps[i + 2]; |
|
else return false; |
|
} |
|
} else if (keyName == "REWIND" && i > 0) { |
|
speed = ps[i - 1]; |
|
if (!speed) { |
|
if (ps[i - 2]) speed = ps[i - 2]; |
|
else return false; |
|
} |
|
} else { |
|
return false; |
|
} |
|
var status = this.player.getStatus(); |
|
this._sendTrace({ |
|
name: keyName.toLowerCase(), |
|
"status": status |
|
}); |
|
speed = parseInt(speed, 10); |
|
this.player.setPlaySpeed(speed); |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: speed, |
|
show: true |
|
}); |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
Player.prototype.setPosition = function Player_setPosition(position) { |
|
var media = this.getCurrentMedia(); |
|
var position = parseInt(position, 10); |
|
var currentPosition = position - media.startTime; |
|
var currentDuration = media.endTime ? (media.endTime - media.startTime) : (media.duration - media.startTime); |
|
if (!media.midReaded && currentPosition > (currentDuration / 2) && media.timeBeforeInsert < (currentDuration / 2)) { |
|
media.midReaded = true; |
|
var inserts = (this.playInserts ? media.getInserts(media.TIME_MID) : false); |
|
} else { |
|
var inserts = (this.playInserts ? media.getLastInserts(position) : false); |
|
} |
|
var hasInsert = false; |
|
var insertList = []; |
|
var status = (this.player ? this.player.getStatus() : false); |
|
this._sendTrace({ |
|
name: "seek", |
|
datas: { |
|
np: position |
|
}, |
|
"status": status |
|
}); |
|
if (inserts) { |
|
var cptInsert = 0; |
|
while (inserts.length != cptInsert) { |
|
cptInsert++; |
|
var insert = inserts[inserts.length - cptInsert]; |
|
if (!insert.ended) { |
|
insertList.push(insert); |
|
hasInsert = true; |
|
} |
|
} |
|
if (hasInsert) { |
|
media.setReprisePosition(position); |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
this._stopPlayer(true); |
|
this.reading = this.reading.concat(insertList); |
|
this.infoBannerInterface.call("HIDE"); |
|
this.playMedia(); |
|
return false; |
|
} else { |
|
this.player.setPosition(position); |
|
} |
|
} else { |
|
this.player.setPosition(position); |
|
} |
|
} |
|
Player.prototype.changeFormat = function Player_changeFormat() { |
|
if (this.formatSelected = this.infoBanner.obj.selFormat(1, true)) { |
|
var formatVal = this.formatSelected.id; |
|
this.CTN.stb.audioVideo.setVideoARConversion(formatVal); |
|
} else {} |
|
} |
|
Player.prototype.getFormats = function Player_getFormats() { |
|
var formats = this.player.getAvailableVideoARConversions(); |
|
var liste = new Array(); |
|
for (var i = 0; i < formats.length; i++) { |
|
liste.push({ |
|
id: formats[i], |
|
format: this.CTN.CONF.FORMATS[formats[i]] |
|
}); |
|
} |
|
return (liste.length ? liste : false); |
|
} |
|
Player.prototype.playNextVideo = function Player_playNextVideo(offset) { |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
}; |
|
if (typeof (offset) != "number") offset = 1; |
|
if (offset != 0) { |
|
var media = this.playList.getMedia(offset); |
|
if (media) { |
|
this.playList.setIndexByOffset(offset); |
|
this.playMedia(media); |
|
} else { |
|
if (this.params.suggestions && (this.params.suggestions.length > 0) && this.partnerCallback) { |
|
this.infoBannerInterface.call("SUGGESTIONS", this.params.suggestions); |
|
} else { |
|
this.quit(); |
|
} |
|
} |
|
} else { |
|
if (this.player) { |
|
this.reading.pop(); |
|
this.playMedia(); |
|
} else { |
|
media = this.playList.getMedia(); |
|
if (media) this.playMedia(media); |
|
} |
|
} |
|
} |
|
Player.prototype.playMedia = function Player_playMedia(media) { |
|
if (!media || !(media.ended && media.onceOnly)) { |
|
if (media) { |
|
this.reading.push(media); |
|
var inserts = (this.playInserts ? media.getInserts(media.TIME_START) : false); |
|
if (inserts) { |
|
var cptInsert = 0; |
|
while (inserts.length != cptInsert) { |
|
cptInsert++; |
|
var insert = inserts[inserts.length - cptInsert]; |
|
if (!insert.ended) this.reading.push(insert); |
|
} |
|
} |
|
} |
|
if (this.reading.length > 0) { |
|
var media = this.reading[this.reading.length - 1]; |
|
if (media.type) { |
|
switch (media.type) { |
|
case media.TYPE_RTSP: |
|
case media.TYPE_HTTP: |
|
this.launchVideo(); |
|
break; |
|
case media.TYPE_ID: |
|
media.idTransaction = media.target; |
|
this.getTransactionInfos(media.target, media.countStream); |
|
break; |
|
case media.TYPE_ASSET: |
|
var userInfos = this.CTN.getInfos(); |
|
var args = media.target; |
|
args.idCrm = userInfos.idcrm; |
|
args.mac = userInfos.mac; |
|
args.partner = this.CTN.getAppli(this.CTN.caller).idSI; |
|
this.CTN.SI.VOD.buy(args, { |
|
obj: this, |
|
fct: '_handleSIResponse', |
|
args: [media] |
|
}, args.partner); |
|
break; |
|
default: |
|
this.quit({ |
|
error: { |
|
internalError: "PV1", |
|
detail: "PB_Playlist_" + (this.playList.index + 1) + "_not valid_type" |
|
} |
|
}); |
|
break; |
|
} |
|
} else { |
|
this.quit({ |
|
error: { |
|
internalError: "PV1", |
|
detail: "PB_Playlist_" + (this.playList.index + 1) + "_not_have_type" |
|
} |
|
}); |
|
} |
|
} else { |
|
this.playNextVideo(); |
|
} |
|
} else { |
|
if (this.reading.length > 0) { |
|
this.reading.pop(); |
|
this.playMedia(); |
|
} else { |
|
this.playNextVideo(); |
|
} |
|
} |
|
} |
|
Player.prototype._handleSIResponse = function Player__handleSIResponse(result, media) { |
|
if (result.isError) { |
|
this.quit({ |
|
error: { |
|
internalError: result.internalError, |
|
detail: result.errorDetails |
|
} |
|
}); |
|
} else { |
|
media.idTransaction = result.idTransaction; |
|
this.getTransactionInfos(result.idTransaction); |
|
} |
|
} |
|
Player.prototype.getCurrentMedia = function Player_getCurrentMedia() { |
|
if (this.reading && this.reading.length > 0) { |
|
return this.reading[this.reading.length - 1]; |
|
} else return false; |
|
} |
|
Player.prototype.launchVideo = function Player_launchVideo() { |
|
var media = this.getCurrentMedia(); |
|
if (!this.launchDelayTimeout) { |
|
if (media.screen) { |
|
this.CTN.setBackground({ |
|
type: this.CTN.BACKGROUND.URL, |
|
data: media.screen |
|
}); |
|
this.infoBannerInterface.call("REFRESH", { |
|
active: false, |
|
speed: 1 |
|
}); |
|
if (media.screenTimeout) { |
|
this.launchDelayTimeout = setTimeout(this.selfName + ".launchVideo();", media.screenTimeout); |
|
return false; |
|
} |
|
} else { |
|
this.CTN.setBackground({ |
|
type: this.CTN.BACKGROUND.NONE |
|
}); |
|
} |
|
} else { |
|
this.launchDelayTimeout = clearTimeout(this.launchDelayTimeout); |
|
} |
|
media.reset(); |
|
this._setTrackingRoutine(true); |
|
this.player = this.CTN.getPlayer(); |
|
this.player.addEventCallback("*", { |
|
obj: this, |
|
fct: "_playerEventListener" |
|
}, false); |
|
this._checkingRoutineOldPacketErrors = 0; |
|
this.playerUpdating = false; |
|
this.DVB_ORIGINAL_PCR_DELAY = this.player.getPCRDelay(); |
|
this.player.setPCRDelay(this.PCR_DELAY); |
|
this._setCheckingRoutine(); |
|
this.CTN.stb.audioVideo.setAudioGain(media.asset ? this.gain : 0); |
|
switch (media.type) { |
|
case media.TYPE_HTTP: |
|
this.player.play({ |
|
type: this.player.SOURCE_HTTP, |
|
url: media.target, |
|
bitrate: media.bitrate |
|
}, true); |
|
break; |
|
case media.TYPE_RTSP: |
|
this.player.play({ |
|
type: this.player.SOURCE_RTSP, |
|
url: media.target, |
|
bitrate: media.bitrate |
|
}, true); |
|
break; |
|
default: |
|
this.quit({ |
|
error: { |
|
internalError: "PV1", |
|
detail: "PB_Playlist_" + (this.playList.index + 1) + "_not_valid_type" |
|
} |
|
}); |
|
break; |
|
} |
|
} |
|
Player.prototype._screenForcedEnded = function Player__screenForcedEnded() { |
|
this.CTN.setBackground({ |
|
type: this.CTN.BACKGROUND.NONE |
|
}); |
|
} |
|
Player.prototype._streamSwapStreamer = function Player__streamSwapStreamer() { |
|
var media = this.getCurrentMedia(); |
|
if (!media || !this.player) return false; |
|
media.getRtspStream(true); |
|
return false; |
|
if (!media.pauseTried) { |
|
var speed = this.player.getCurrentPlaySpeed(); |
|
this.player.setPlaySpeed(0); |
|
media.pauseTried = true; |
|
setTimeout(this.selfName + ".player.setPlaySpeed(" + speed + ");", 500); |
|
return true; |
|
} |
|
if (media.type == media.TYPE_RTSP) { |
|
if (nextStream = media.getRtspStream(true)) { |
|
media.setReprisePosition(media.position); |
|
media.oldStats = media.stats; |
|
var status = (this.player ? this.player.getStatus() : false); |
|
this._sendTrace({ |
|
name: "failover", |
|
type: this.CTN.CONF.LOG.TYPES.QOS, |
|
"status": status |
|
}); |
|
this.player.play({ |
|
type: media.playerType, |
|
url: nextStream, |
|
bitrate: media.bitrate |
|
}, true); |
|
this.playerUpdating = false; |
|
return true; |
|
} else {} |
|
} else {} |
|
return false; |
|
} |
|
Player.prototype._checkingRoutine = function Player__checkingRoutine() { |
|
if (this.stopping) { |
|
return false; |
|
} |
|
var player = this.player; |
|
if (this.launchDelayTimeout) return false; |
|
if (player) { |
|
var status = player.getStatus(); |
|
if (status.access & player.STATUS_ACCESS_OK) { |
|
var media = this.getCurrentMedia(); |
|
if (status.state == player.STATUS_STATE_PLAYING || status.state == player.STATUS_STATE_PAUSED || status.state == player.STATUS_STATE_FFORWARD || status.state == player.STATUS_STATE_FREWIND) { |
|
var stats = player.getStats(); |
|
media.setStats(stats); |
|
var position = player.getCurrentPosition(); |
|
if (position > media.duration) return; |
|
media.setPosition(position); |
|
if (position < media.startTime) { |
|
media.setReprisePosition(media.startTime); |
|
} |
|
if (media.reprisePosition && (position < (media.reprisePosition - this.reprisePositionMini) || position > (media.reprisePosition + this.reprisePositionMini))) { |
|
this._setCheckingRoutine(10000); |
|
player.setPosition(media.reprisePosition); |
|
media.setReprisePosition(false); |
|
media.repriseEnCours = true; |
|
} else if (media.repriseEnCours) { |
|
this._setCheckingRoutine(); |
|
media.repriseEnCours = null; |
|
} |
|
if (status.state == player.STATUS_STATE_PAUSED) { |
|
var infosBI = new Object(); |
|
infosBI.position = position - media.startTime; |
|
infosBI.speed = this.player.getCurrentPlaySpeed(); |
|
this.infoBannerInterface.call("REFRESH", infosBI); |
|
} else if (position == this._checkingRoutineOldPosition) { |
|
if (position && position > 0) { |
|
this._checkingRoutineAlert(false, "position fixed"); |
|
} else { |
|
this._checkingRoutineAlert(true, "position fixed"); |
|
} |
|
return; |
|
} else if (media.endTime && position > media.endTime && position < player.getDuration()) { |
|
this.mediaEnded(); |
|
} else { |
|
var speed = player.getCurrentPlaySpeed(); |
|
speed = (speed ? speed : 0); |
|
if (speed != this.oldSpeed && this.infoBannerLoaded) { |
|
this._setCheckingRoutine(); |
|
} |
|
this.oldSpeed = speed; |
|
var currentPosition = position - media.startTime; |
|
var currentDuration = media.endTime ? (media.endTime - media.startTime) : (media.duration - media.startTime); |
|
if (!media.midReaded && currentPosition > (currentDuration / 2) && media.timeBeforeInsert < (currentDuration / 2)) { |
|
media.midReaded = true; |
|
var inserts = (this.playInserts ? media.getInserts(media.TIME_MID) : false); |
|
} else { |
|
var inserts = (this.playInserts ? media.getLastInserts(position) : false); |
|
} |
|
var hasInsert = false; |
|
var insertList = []; |
|
if (inserts) { |
|
var cptInsert = 0; |
|
while (inserts.length != cptInsert) { |
|
cptInsert++; |
|
var insert = inserts[inserts.length - cptInsert]; |
|
if (!insert.ended) { |
|
insertList.push(insert); |
|
hasInsert = true; |
|
} |
|
} |
|
if (hasInsert) { |
|
media.setReprisePosition(position); |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
this._stopPlayer(true); |
|
this.reading = this.reading.concat(insertList); |
|
this.infoBannerInterface.call("HIDE"); |
|
this.playMedia(); |
|
return false; |
|
} |
|
} |
|
var infosBI = new Object(); |
|
infosBI.position = position - media.startTime; |
|
infosBI.active = media.infoBanner; |
|
if (!this.playerUpdating && (!media.componentsDefined || media.componentsToRefresh)) { |
|
infosBI.audios = this.player.getAvailableAudio(); |
|
if (!isDefined(infosBI.audios)) infosBI.audios = false; |
|
infosBI.audioSelected = 0; |
|
var currentAudio = this.player.getCurrentAudio(); |
|
for (var aud = 0; aud < infosBI.audios.length; aud++) { |
|
infosBI.audios[aud].name = (this.CTN.CONF.LANGUAGES[infosBI.audios[aud].language] ? this.CTN.CONF.LANGUAGES[infosBI.audios[aud].language] : "Audio " + (aud + 1)); |
|
if (currentAudio.pid == infosBI.audios[aud].pid) infosBI.audioSelected = aud; |
|
} |
|
infosBI.subtitles = new Array({ |
|
"pid": "0", |
|
"language": "no" |
|
}); |
|
infosBI.subtitleSelected = 0; |
|
var currentSubtitle = this.player.getCurrentSubtitles(); |
|
var additionalSubtitles = this.player.getAvailableSubtitles(); |
|
if (additionalSubtitles && additionalSubtitles.length) infosBI.subtitles = infosBI.subtitles.concat(player.getAvailableSubtitles()); |
|
for (var sub = 0; sub < infosBI.subtitles.length; sub++) { |
|
infosBI.subtitles[sub].name = (!infosBI.subtitles[sub].hearingImpaired ? (this.CTN.CONF.LANGUAGES[infosBI.subtitles[sub].language] ? this.CTN.CONF.LANGUAGES[infosBI.subtitles[sub].language] : "Sous-titre " + (sub + 1)) : "Malentendant"); |
|
if (currentSubtitle && currentSubtitle.pid == infosBI.subtitles[sub].pid) infosBI.subtitleSelected = sub; |
|
} |
|
infosBI.formats = this.getFormats(); |
|
var currentFormat = this.CTN.stb.audioVideo.getVideoARConversion(); |
|
for (var i = 0; i < infosBI.formats.length; i++) { |
|
if (currentFormat == infosBI.formats[i].id) { |
|
infosBI.formatSelected = i; |
|
} |
|
} |
|
if (infosBI.audios && infosBI.subtitles) { |
|
media.audios = infosBI.audios; |
|
media.subtitles = infosBI.subtitles; |
|
media.formats = infosBI.formats; |
|
media.componentsDefined = true; |
|
media.componentsToRefresh = false; |
|
} |
|
} |
|
this.infoBannerInterface.call("REFRESH", infosBI); |
|
this.CTN.KM.setActive(true); |
|
} |
|
this._checkingRoutineOldPosition = position; |
|
if (media && media.stats && media.stats.errors > this._checkingRoutineOldPacketErrors && new Date() - this._checkingEDLastDone > 3600) { |
|
this._checkingRoutineOldPacketErrors = media.stats.errors; |
|
this._checkingEDLastDone = new Date(); |
|
this.setTrace("ED"); |
|
this._checkingRoutineAlert(false, "ED"); |
|
} else { |
|
if (this._checkingRoutineMinorCpt > 0) this._checkingRoutineMinorCpt--; |
|
} |
|
} else if (status.state == player.STATUS_STATE_REWINDED) {} else if (status.state == player.STATUS_STATE_LOADING) { |
|
this._checkingRoutineAlert((media.isInsert ? false : true), "keep loading"); |
|
} else { |
|
this._checkingRoutineAlert(true, "not playing"); |
|
} |
|
} else { |
|
this._checkingRoutineAlert(true, "access nok"); |
|
} |
|
} else { |
|
this._checkingRoutineAlert(true, "no player"); |
|
} |
|
} |
|
Player.prototype._checkingRoutineAlert = function Player__checkingRoutineAlert(highFailure, reason, raiseError) { |
|
if (highFailure) this._checkingRoutineMajorCpt++; |
|
else this._checkingRoutineMinorCpt++; |
|
var media = this.getCurrentMedia(); |
|
var status = (this.player ? this.player.getStatus() : false); |
|
if (this._checkingRoutineMinorCpt >= this._checkingRoutineMinorMax) { |
|
this._checkingRoutineMinorCpt = 0; |
|
this._checkingRoutineMajorCpt++; |
|
} |
|
if (this._checkingRoutineMajorCpt >= this._checkingRoutineMajorMax) { |
|
if (media.isInsert) { |
|
this.setTrace("error"); |
|
this.playInserts = false; |
|
this.reading.pop(); |
|
if (this.player) { |
|
log("STOP", "STOP", 0); |
|
this.player.stop(); |
|
}; |
|
this.playMedia(); |
|
} else { |
|
if (this.player) { |
|
if (highFailure || raiseError) this.quit({ |
|
error: { |
|
internalError: "PK1", |
|
detail: (reason ? reason : "") |
|
} |
|
}); |
|
else { |
|
this._checkingRoutineMajorCpt = this._checkingRoutineMinorCpt = 0; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
Player.prototype._setCheckingRoutine = function Player__setCheckingRoutine(speed) { |
|
if (this._checkingTimeout) this._checkingTimeout = clearTimeout(this._checkingTimeout); |
|
if (this._checkingInterval) this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineOldPosition = 0; |
|
this._checkingRoutineMinorCpt = 0; |
|
this._checkingRoutineMajorCpt = 0; |
|
speed = (speed > 1000 ? speed : this._checkingTime); |
|
this._checkingTimeout = setTimeout(this.selfName + "._checkingRoutine();", speed / 2); |
|
this._checkingInterval = setInterval(this.selfName + "._checkingRoutine(" + speed + ");", speed); |
|
} |
|
Player.prototype._setTrackingRoutine = function Player__setTrackingRoutine(stop) { |
|
if (this._trackingTimeout) this._trackingTimeout = clearTimeout(this._trackingTimeout); |
|
if (!stop) this._trackingTimeout = setTimeout(this.selfName + "._trackingRoutine(0);", this.trackingPositions[0]); |
|
} |
|
Player.prototype._trackingRoutine = function Player__trackingRoutine(indexPosition) { |
|
var player = this.player; |
|
if (player) { |
|
var status = player.getStatus(); |
|
if (status.access & player.STATUS_ACCESS_OK) { |
|
var media = this.getCurrentMedia(); |
|
if (status.state == player.STATUS_STATE_PLAYING || status.state == player.STATUS_STATE_PAUSED || status.state == player.STATUS_STATE_FFORWARD || status.state == player.STATUS_STATE_FREWIND) { |
|
var nextTracking = this.trackingPositions.length - 1 > indexPosition ? indexPosition + 1 : this.trackingPositions.length - 1; |
|
this._sendTrace({ |
|
name: "alive", |
|
type: this.CTN.CONF.LOG.TYPES.AUDIENCE, |
|
"status": status |
|
}); |
|
this._trackingTimeout = setTimeout(this.selfName + "._trackingRoutine(" + nextTracking + ");", this.trackingPositions[nextTracking]); |
|
} |
|
} |
|
} |
|
} |
|
Player.prototype.playPause = function Player_playPause() { |
|
if (!this.player || this.trickmodesBlocked) return false; |
|
this.trickmodesBlocked = true; |
|
this.timeoutTrickmode = setTimeout(this.selfName + "._unblockTrickmodes();", this.TIMER_TRICKMODES); |
|
var status = this.player.getStatus(); |
|
if (status.state == this.player.STATUS_STATE_PAUSED || this.player.getCurrentPlaySpeed() != 1) { |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 1 |
|
}); |
|
this._sendTrace({ |
|
name: "play", |
|
"status": status |
|
}); |
|
var media = this.getCurrentMedia(); |
|
this.player.setPlaySpeed(1); |
|
} else if (status.state == this.player.STATUS_STATE_PLAYING) { |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 0, |
|
show: true |
|
}); |
|
this._sendTrace({ |
|
name: "pause", |
|
"status": status |
|
}); |
|
this.player.setPlaySpeed(1); |
|
this.player.setPlaySpeed(0); |
|
} |
|
} |
|
Player.prototype.getTransactionInfos = function Player_getTransactionInfos(idTransaction, countStream) { |
|
var params = { |
|
"transactionId": idTransaction, |
|
"countStream": (countStream === true || (!isDefined(countStream) && this.countStream) ? true : false) |
|
}; |
|
this.CTN.SI.VOD.getUrlRtsp(params, { |
|
obj: this, |
|
fct: "_getTransactionInfosCallback" |
|
}); |
|
} |
|
Player.prototype._getTransactionInfosCallback = function Player__getTransactionInfosCallback(result) { |
|
if (!(obj = this._checkResult(result, "getUrlRtsp"))) return; |
|
var media = this.reading[this.reading.length - 1]; |
|
var asset = obj.asset; |
|
if (!asset) { |
|
result.detail = "getUrlRtsp asset not defined"; |
|
this.quit({ |
|
error: result |
|
}); |
|
return; |
|
} |
|
if (asset.bitrate) media.bitrate = parseInt(asset.bitrate, 10); |
|
if (media.categorie === false) media.categorie = parseInt(asset.asset_categorie, 10); |
|
media.setAsset(asset); |
|
var rtspStreamList = new Array(); |
|
if (isDefined(asset.asset_rtsp_backup) && typeof asset.asset_rtsp_backup == "string") { |
|
rtsp_first = asset.asset_rtsp_backup; |
|
rtspStreamList.splice(0, 0, asset.asset_rtsp_backup); |
|
} |
|
if (isDefined(asset.asset_rtsp_secondary) && typeof asset.asset_rtsp_secondary == "string") { |
|
rtsp_first = asset.asset_rtsp_secondary; |
|
rtspStreamList.splice(0, 0, asset.asset_rtsp_secondary); |
|
} |
|
if (isDefined(asset.asset_rtsp_primary) && typeof asset.asset_rtsp_primary == "string") { |
|
rtsp_first = asset.asset_rtsp_primary; |
|
rtspStreamList.splice(0, 0, asset.asset_rtsp_primary); |
|
} |
|
media.setRtspStreamList(rtspStreamList); |
|
this.launchVideo(); |
|
} |
|
Player.prototype._playerEventListener = function Player__playerEventListener(status) { |
|
if (this.stopping) { |
|
return false; |
|
} |
|
if (this._checkingInterval) { |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
var media = this.getCurrentMedia(); |
|
if (!media) return; |
|
media.setStatus(getSource(status)); |
|
var stats = this.player.getStats(); |
|
media.setStats(stats); |
|
var position = this.player.getCurrentPosition(); |
|
var duration = this.player.getDuration(); |
|
if (media.reprisePosition) { |
|
media.setPosition(media.reprisePosition); |
|
} else if (isDefined(position) && isDefined(duration) && position <= duration) { |
|
media.setPosition(position); |
|
} |
|
var now = new Date(); |
|
if (status.access == this.player.STATUS_ACCESS_NORESOURCE) { |
|
this._sendTrace({ |
|
name: "noRessources", |
|
type: this.CTN.CONF.LOG.TYPES.INTERNAL, |
|
"status": status |
|
}); |
|
this.quit({ |
|
error: { |
|
internalError: "NO_RESSOURCE", |
|
detail: "STATUS_ACCESS_NORESOURCE" |
|
} |
|
}); |
|
} else if (status.type == this.player.EVENT_RIGHTS_CHANGED) { |
|
switch (status.rights) { |
|
case this.player.STATUS_RIGHTS_DESCRAMBLING: |
|
this._sendTrace({ |
|
name: "drmdetect", |
|
type: this.CTN.CONF.LOG.TYPES.INTERNAL, |
|
"status": status |
|
}); |
|
break; |
|
case this.player.STATUS_RIGHTS_DESCRAMBLED: |
|
this._sendTrace({ |
|
name: "drmdecrypt", |
|
type: this.CTN.CONF.LOG.TYPES.INTERNAL, |
|
"status": status |
|
}); |
|
if (!media.visuConfirmed) { |
|
this.confirmVisualisation(); |
|
} |
|
break; |
|
case this.player.STATUS_RIGHTS_OTHER: |
|
this.CTN.KM.setActive(false); |
|
this.quit({ |
|
error: { |
|
internalError: "PC9", |
|
detail: "pb_verimatrix:" + (isDefined(status.detail) ? status.detail : "") |
|
} |
|
}); |
|
break; |
|
case this.player.STATUS_RIGHTS_NONE: |
|
this.CTN.KM.setActive(false); |
|
this.tryGettingRights(media.idTransaction); |
|
break; |
|
} |
|
} else if (!media.started && status.type == this.player.EVENT_STATE_CHANGED && status.access & this.player.STATUS_ACCESS_OK && status.state == this.player.STATUS_STATE_PLAYING) { |
|
media.started = true; |
|
this.CTN.setBackground({ |
|
type: this.CTN.BACKGROUND.NONE |
|
}); |
|
this._sendTrace({ |
|
name: "playing", |
|
"status": status |
|
}); |
|
this._setTrackingRoutine(); |
|
var infosBI = new Object(); |
|
infosBI.active = media.infoBanner; |
|
infosBI.speed = 1; |
|
infosBI.position = 0; |
|
media.duration = duration; |
|
infosBI.duration = media.endTime ? (media.endTime - media.startTime) : (media.duration - media.startTime); |
|
infosBI.name = media.name; |
|
infosBI.synopsis = media.synopsis; |
|
infosBI.index = media.isInsert ? this.playList.getMedia().index : media.index; |
|
infosBI.infoBanner = media.infoBanner; |
|
infosBI.trickMode = media.trickMode; |
|
infosBI.emcs = media.emcs; |
|
infosBI.chapters = media.chapters; |
|
infosBI.refresh = true; |
|
if (media.componentsDefined) { |
|
infosBI.audios = media.audios; |
|
infosBI.subtitles = media.subtitles; |
|
infosBI.formats = media.formats; |
|
} |
|
this.infoBannerInterface.call("REFRESH", infosBI); |
|
if (media.reprisePosition || media.startTime) { |
|
if (!media.reprisePosition) media.setReprisePosition(media.startTime); |
|
this._sendTrace({ |
|
name: "recover", |
|
datas: { |
|
np: media.reprisePosition |
|
}, |
|
"status": status |
|
}); |
|
} |
|
} else if (status.state == this.player.STATUS_STATE_LOADING) { |
|
this._sendTrace({ |
|
name: "loading", |
|
"status": status |
|
}); |
|
} else if (status.state == this.player.STATUS_STATE_FINISHED) { |
|
if (this.player.getCurrentPlaySpeed() < 0) { |
|
this.player.setPlaySpeed(1); |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 1, |
|
show: true |
|
}); |
|
} else { |
|
if (!media.ended) { |
|
this.mediaEnded(); |
|
} |
|
} |
|
} else if (status.state == this.player.STATUS_STATE_STOPPED) {} else if (status.state == this.player.STATUS_STATE_REWINDED) { |
|
this.player.setPlaySpeed(1); |
|
this._sendTrace({ |
|
name: "rewinded", |
|
"status": status |
|
}); |
|
this.infoBannerInterface.call("REFRESH", { |
|
speed: 1 |
|
}); |
|
} else if (status.state == this.player.STATUS_STATE_OTHER && (status.rights == this.player.STATUS_RIGHTS_NONE || status.rights == this.player.STATUS_RIGHTS_OTHER)) { |
|
this.CTN.KM.setActive(false); |
|
if (status.rights == this.player.STATUS_RIGHTS_OTHER) this.quit({ |
|
error: { |
|
internalError: "PC9", |
|
detail: "pb_verimatrix:" + (isDefined(status.detail) ? status.detail : "") |
|
} |
|
}); |
|
else this.tryGettingRights(media.idTransaction); |
|
} else if (!(status.access & this.player.STATUS_ACCESS_OK) || status.state == this.player.STATUS_STATE_UNSUPPORTED || (status.type == this.player.EVENT_STATE_CHANGED && status.state & this.player.STATUS_STATE_OTHER)) { |
|
if (media.isInsert) { |
|
this._sendTrace({ |
|
name: "error", |
|
type: this.CTN.CONF.LOG.TYPES.ERROR, |
|
"status": status |
|
}); |
|
this.playInserts = false; |
|
this.reading.pop(); |
|
if (this.player) { |
|
this.player.stop() |
|
}; |
|
this.playMedia(); |
|
} else { |
|
if (status.access & this.player.STATUS_ACCESS_NOK || status.access == this.player.STATUS_ACCESS_NOT_FOUND) { |
|
var toLog = "PLAYER--ACCESS_" + this.player._STATUS_ACCESS_VALUE_TO_NAME[status.access] + "--STATUS_" + this.player._STATUS_STATE_VALUE_TO_NAME[status.state]; |
|
this.quit({ |
|
error: { |
|
internalError: (status.access & this.player.STATUS_ACCESS_NOK ? "PK0" : "PK1"), |
|
detail: "pb_kasenna:" + (status.detail ? status.detail : "") |
|
} |
|
}) |
|
} |
|
} |
|
} |
|
} |
|
Player.prototype.tryGettingRights = function Player_tryGettingRights(idTransaction) { |
|
var params = { |
|
"transactionId": idTransaction, |
|
"mac": this.CTN.getInfos().mac |
|
}; |
|
this.CTN.SI.VOD.updateRights(params, { |
|
obj: this, |
|
fct: "_tryGettingRightsCallback" |
|
}); |
|
} |
|
Player.prototype._tryGettingRightsCallback = function Player__tryGettingRightsCallback(result) { |
|
if (!(obj = this._checkResult(result, "updateRight"))) return; |
|
var media = this.getCurrentMedia(); |
|
if (media.setRightsReloaded()) { |
|
this.launchVideo(); |
|
} else { |
|
this.quit({ |
|
error: { |
|
internalError: "PC1", |
|
detail: "noRights" |
|
} |
|
}); |
|
} |
|
} |
|
Player.prototype.confirmVisualisation = function Player_confirmVisualisation() { |
|
var media = this.getCurrentMedia(); |
|
if (media.type == media.TYPE_RTSP) { |
|
var params = { |
|
"transactionId": media.idTransaction, |
|
"nokInfo": "" |
|
}; |
|
this.CTN.SI.VOD.confirm(params, { |
|
obj: this, |
|
fct: "_confirmVisuCallback", |
|
args: [media.idTransaction] |
|
}); |
|
} else { |
|
media.setVisuConfirmed(); |
|
} |
|
} |
|
Player.prototype._confirmVisuCallback = function Player__confirmVisuCallback(result, idTransaction) { |
|
if (!(obj = this._checkResult(result, "confirmVisu"))) return; |
|
var media = this.getCurrentMedia(); |
|
if (media.idTransaction == idTransaction) { |
|
var status = (this.player ? this.player.getStatus() : false); |
|
this._sendTrace({ |
|
name: "confirmed", |
|
"status": status |
|
}); |
|
media.setVisuConfirmed(); |
|
} |
|
} |
|
Player.prototype._checkResult = function Player__checkResult(result, detail) { |
|
if (result && result.isError) { |
|
result.detail = detail + (result.errorDetails ? ":" + result.errorDetails : ""); |
|
this.quit({ |
|
error: result |
|
}); |
|
return false; |
|
} |
|
return result; |
|
} |
|
Player.prototype.mediaEnded = function Player_mediaEnded() { |
|
var media = this.getCurrentMedia(); |
|
var status = (this.player ? this.player.getStatus() : false); |
|
this._sendTrace({ |
|
name: "ended", |
|
"status": status |
|
}); |
|
if (this.player) { |
|
this.player.removeEventCallback("*", { |
|
obj: this, |
|
fct: "_playerEventListener" |
|
}, false); |
|
this.player.setSubtitles(null); |
|
this.player.stop(); |
|
this.player.setSubtitles(null); |
|
delete(this.player); |
|
} |
|
this.infoBannerInterface.call("HIDE"); |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
if (media) { |
|
media.setEnded(); |
|
this.reading.pop(); |
|
var inserts = (this.playInserts ? media.getInserts(media.TIME_END) : false); |
|
if (inserts) { |
|
var cptInsert = 0; |
|
while (inserts.length != cptInsert) { |
|
cptInsert++; |
|
var insert = inserts[inserts.length - cptInsert]; |
|
if (!insert.ended) this.reading.push(insert); |
|
} |
|
} |
|
if (this.player) { |
|
this.player.setSubtitles(null); |
|
this.player.removeEventCallback("*", { |
|
obj: this, |
|
fct: "_playerEventListener" |
|
}, false); |
|
delete(this.player); |
|
} |
|
this.playMedia(); |
|
} |
|
} |
|
Player.prototype.setTrace = function Player_setTrace(action) { |
|
var media = this.getCurrentMedia(); |
|
if (!media || action == "quit" || action == "start") { |
|
this.playList.report[action] = new Date().getTime(); |
|
} else { |
|
media._setTrace(action); |
|
} |
|
try { |
|
if (!this.isUnload && this.partnerCallback) this.partnerCallback.call(action, (media ? media : false)); |
|
} catch (e) {} |
|
} |
|
Player.prototype._sendTrace = function Player__sendTrace(trace) { |
|
this.setTrace(trace.name); |
|
if (trace.type == this.CTN.CONF.LOG.TYPES.DEBUG) return; |
|
var details = ""; |
|
if (trace && isDefined(trace.datas) && trace.datas.detail) { |
|
details = trace.datas.detail; |
|
delete(trace.datas.detail); |
|
} |
|
var logType = (trace.type ? trace.type : this.CTN.CONF.LOG.TYPES.NAV); |
|
var datas = this.getDatasToLog(); |
|
datas.push(["act", trace.name]); |
|
if (trace.status) { |
|
details = this._addStatusInDetails(details, trace.status); |
|
delete(trace.status); |
|
} |
|
if (isDefined(trace.datas)) { |
|
for (var i in trace.datas) { |
|
datas.push([i, trace.datas[i]]); |
|
} |
|
} |
|
this.CTN.pushLog(logType, datas, details); |
|
} |
|
Player.prototype._addStatusInDetails = function Player__addStatusInDetails(details, status) { |
|
if (!status) return details; |
|
var statusStr = ""; |
|
var toDebug = ["access", "state", "rights", "morality"]; |
|
for (index in toDebug) { |
|
statusStr += (isDefined(status[toDebug[index]]) && typeof (status[toDebug[index]]) == "number" ? status[toDebug[index]].toString(16) : "0") + ":"; |
|
} |
|
statusStr = statusStr.substring(0, statusStr.length - 1); |
|
if (details) statusStr += "//"; |
|
details = statusStr + details; |
|
return details; |
|
} |
|
Player.prototype.getDatasToLog = function Player_getDatasToLog() { |
|
var datas = new Array(); |
|
var media = this.getCurrentMedia(); |
|
if (media && !media.isInsert) { |
|
if (this.params.tags) { |
|
var tags = this.params.tags; |
|
for (var i in tags) { |
|
datas.push([i, (isDefined(tags[i]) ? tags[i] : "")]); |
|
} |
|
} |
|
if (media.tags) { |
|
var tags = media.tags; |
|
for (var i in tags) { |
|
datas.push([i, (isDefined(tags[i]) ? tags[i] : "")]); |
|
} |
|
} |
|
} |
|
datas.push(["vcas", this.CTN.stb.condAccess.getVerimatrixServer()]); |
|
if (!this.playList) return datas; |
|
if (!media) return datas; |
|
datas.push(["vty", media.isInsert ? 0 : 1]); |
|
datas.push(["tspt", (isDefined(media.type) ? media.type : "")]); |
|
datas.push(["ast", (isDefined(media.asset) && isDefined(media.asset.asset_id) ? media.asset.asset_id : "")]); |
|
datas.push(["trid", (isDefined(media.idTransaction) ? media.idTransaction : "")]); |
|
var position = (isDefined(media.oldPosition) ? media.oldPosition : media.position); |
|
datas.push(["pos", (isDefined(position) ? position : "")]); |
|
var duration = media.endTime ? (media.endTime - media.startTime) : (media.duration - media.startTime); |
|
datas.push(["drt", (isDefined(duration) ? duration : "")]); |
|
datas.push(["lp", (isDefined(media.lastPositionEvent) ? media.lastPositionEvent : "")]); |
|
media.lastPositionEvent = position; |
|
var cs = ""; |
|
if (this.player) var cs = this.player.getCurrentPlaySpeed(); |
|
datas.push(["spd", (isDefined(cs) ? cs : "")]); |
|
var stats = (isDefined(media.oldStats) ? media.oldStats : media.stats); |
|
var qos = (isDefined(stats) && stats.packets ? stats.packets : 0); |
|
qos += "/" + (isDefined(stats) && stats.errors ? stats.errors : 0); |
|
qos += "/" + (isDefined(stats) && stats.missingRtpPackets ? stats.missingRtpPackets : 0); |
|
qos += "/" + (isDefined(stats) && stats.correctedRtpPackets ? stats.correctedRtpPackets : 0); |
|
datas.push(["qos", qos]); |
|
datas.push(["src", media.getStreamer() + "::" + media.getStreamName()]); |
|
return datas; |
|
} |
|
Player.prototype.quit = function Player_quit(params) { |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
if (this.stopping && !this.stoppingPlayer) return true; |
|
this.infoBannerInterface = false; |
|
this.infoBannerLoaded = false; |
|
this.CTN.appliClose("infoBanner"); |
|
if (params) { |
|
this.stoppingParams = params; |
|
this.stoppedStreamer = isDefined(this.player) && isDefined(this.player.currentMediaSource) ? this.player.currentMediaSource.url : ""; |
|
} |
|
if (this.player) { |
|
this._stopPlayer(); |
|
this.CTN.KM.setActive(false); |
|
setTimeout(this.selfName + ".quit();", 2000); |
|
return false; |
|
} |
|
this.CTN.stb.audioVideo.setVideoARConversion(this.DVB_ORIGINAL_FORMAT); |
|
this.CTN.stb.audioVideo.setAudioGain(this.DVB_ORIGINAL_GAIN_AUDIO); |
|
this.stopping = true; |
|
this.stoppingPlayer = false; |
|
var videoToSave = this.playList.getVideoToSave(); |
|
if (this.playList.id && (!videoToSave || (videoToSave && videoToSave.started))) { |
|
var cookieToSave = ""; |
|
if (videoToSave && videoToSave.idRecovery) { |
|
var position = (isDefined(videoToSave.oldPosition) ? videoToSave.oldPosition : videoToSave.position); |
|
if (typeof (position) == "number" && !isNaN(position) && position > this.reprisePositionMini) cookieToSave = (videoToSave.ended ? "" : this.playList.id + "|" + videoToSave.idRecovery + "|" + position + "|" + videoToSave.index); |
|
} |
|
if (this.cookie) { |
|
var svgPls = this.cookie.split(";"); |
|
var cpt = 0; |
|
for (var i = 0; i < svgPls.length; i++) { |
|
var fields = svgPls[i].split("|"); |
|
if (fields[0] == this.playList.id) { |
|
continue; |
|
} |
|
if (cpt < this._cookieMaxSavePls) { |
|
cpt++; |
|
if (cookieToSave) cookieToSave += ";"; |
|
cookieToSave += svgPls[i]; |
|
} |
|
} |
|
} |
|
if (cookieToSave || cookieToSave == "") { |
|
this.CTN.appliSetSetting(this.selfName + ".playListIds", cookieToSave); |
|
} |
|
} |
|
if (this._checkingTimeout) this._checkingTimeout = clearTimeout(this._checkingTimeout); |
|
if (this._checkingInterval) this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._sendTrace({ |
|
name: "quit" |
|
}); |
|
var report = (this.report ? this.playList.getReport() : false); |
|
if (this.stoppingParams && this.stoppingParams.error) { |
|
this.setTrace("error"); |
|
this.stoppingParams.error.params = this.getDatasToLog(); |
|
this.stoppingParams.paramsBack = (this.params.paramsBack ? this.params.paramsBack : this.params); |
|
if (report) { |
|
if (!this.stoppingParams.paramsBack || !typeof (this.stoppingParams.paramsBack) == "object") this.stoppingParams.paramsBack = new Object(); |
|
this.stoppingParams.paramsBack.report = report; |
|
} |
|
setTimeout(this.selfName + ".CTN.appliLoad(\"error\", " + this.selfName + ".stoppingParams);", 1000); |
|
} else { |
|
if (!this.stoppingParams) this.stoppingParams = new Object(); |
|
if (report) this.stoppingParams.report = report; |
|
setTimeout(this.selfName + ".CTN.goBack(" + this.selfName + ".stoppingParams);", 1000); |
|
} |
|
} |
|
Player.prototype._stopPlayer = function Player__stopPlayer(suspended) { |
|
if (this._checkingInterval) { |
|
this._checkingInterval = clearInterval(this._checkingInterval); |
|
this._checkingRoutineMinorCpt = 0; |
|
} |
|
this._setTrackingRoutine(false); |
|
if (isDefined(this.player) && this.player) { |
|
var status = (this.player ? this.player.getStatus() : false); |
|
if (suspended) { |
|
this._sendTrace({ |
|
name: "suspended", |
|
"status": status |
|
}); |
|
} else { |
|
this._sendTrace({ |
|
name: "stopped", |
|
"status": status |
|
}); |
|
} |
|
this.player.setSubtitles(null); |
|
this.player.removeEventCallback("*", { |
|
obj: this, |
|
fct: "_playerEventListener" |
|
}, false); |
|
this.player.setPCRDelay(this.DVB_ORIGINAL_PCR_DELAY); |
|
this.player.stop(); |
|
this.setTrace("stopped"); |
|
delete(this.player); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
function Media(selfName, media, isInsert) { |
|
this.isInsert = isInsert ? true : false; |
|
this.selfName = selfName; |
|
this.DEBUG_ID = 3; |
|
this.traces = new Array(); |
|
this.type = false; |
|
this.asset = false; |
|
this.id = false; |
|
this.midReaded = false; |
|
this.timeBeforeInsert = 0; |
|
if (isDefined(media.id)) this.id = media.id; |
|
if (isDefined(media.name)) this.name = media.name; |
|
if (isDefined(media.subtitle)) this.subtitle = media.subtitle; |
|
if (isDefined(media.bitrate)) this.bitrate = media.bitrate; |
|
if (isDefined(media.target)) this.target = media.target; |
|
if (isDefined(media.desc)) this.desc = media.desc; |
|
if (isDefined(media.image)) this.image = media.image; |
|
if (isDefined(media.tags)) this.tags = media.tags; |
|
if (isDefined(media.infoBanner)) this.infoBanner = media.infoBanner; |
|
if (isDefined(media.trickMode)) this.trickMode = media.trickMode; |
|
if (isDefined(media.onceOnly)) this.onceOnly = media.onceOnly; |
|
if (isDefined(media.screen)) this.screen = media.screen; |
|
if (isDefined(media.screenTimeout)) this.screenTimeout = media.screenTimeout; |
|
if (isDefined(media.endTime)) this.endTime = media.endTime; |
|
if (isDefined(media.startTime)) this.startTime = media.startTime; |
|
if (isDefined(media.duration)) this.duration = media.duration; |
|
if (isDefined(media.inserts)) this.inserts = media.inserts; |
|
if (isDefined(media.chapters)) this.chapters = media.chapters; |
|
if (isDefined(media.emcs)) this.emcs = media.emcs; |
|
this.setType(this.target); |
|
if (typeof (this.startTime) != "number") { |
|
this.startTime = (typeof (this.startTime) == "string" ? parseInt(this.startTime, 10) : 0); |
|
} |
|
if (typeof (this.endTime) != "number") { |
|
this.endTime = (typeof (this.endTime) == "string" ? parseInt(this.endTime, 10) : 0); |
|
} |
|
if (typeof (this.duration) != "number") { |
|
this.duration = (typeof (this.duration) == "string" ? parseInt(this.duration, 10) : false); |
|
} |
|
if (this.duration) this.endTime = this.startTime + this.duration; |
|
if (typeof (this.screenTimeout) != "number") { |
|
this.screenTimeout = (typeof (this.screenTimeout) == "string" ? parseInt(this.screenTimeout, 10) : 3000); |
|
} |
|
if (typeof (this.screenTimeout) == "number" && this.screenTimeout < 3000) { |
|
this.screenTimeout = 3000; |
|
} |
|
if (!this.bitrate || typeof (this.bitrate) != "number") { |
|
this.bitrate = (typeof (this.bitrate) == "string" ? parseInt(this.bitrate, 10) : false); |
|
} |
|
if (!this.isInsert) { |
|
this.trickMode = ((this.trickMode === false || this.trickMode === "false") ? false : true); |
|
this.infoBanner = ((this.infoBanner === false || this.infoBanner === "false") ? false : true); |
|
this.onceOnly = ((this.onceOnly === true || this.onceOnly === "true") ? true : false); |
|
if (this.inserts) { |
|
this.initInserts(this.inserts); |
|
} else { |
|
this.inserts = false; |
|
} |
|
this.initChapters(this.chapters); |
|
} else { |
|
this.trickMode = false; |
|
this.infoBanner = false; |
|
this.onceOnly = true; |
|
} |
|
} |
|
Media.prototype.TIME_START = "START"; |
|
Media.prototype.TIME_END = "END"; |
|
Media.prototype.TIME_MID = "MID"; |
|
Media.prototype.TYPE_HTTP = "HTTP"; |
|
Media.prototype.TYPE_RTSP = "RTSP"; |
|
Media.prototype.TYPE_ID = "ID"; |
|
Media.prototype.TYPE_ASSET = "ASSET"; |
|
Media.prototype.initChapters = function Media_initChapters(chapters) { |
|
var chapterList = new Array(); |
|
for (var i in chapters) { |
|
var chapter = chapters[i]; |
|
if (isDefined(chapter.position)) { |
|
var isSet = false; |
|
var chaptersCopy = chapterList.slice(0); |
|
for (var j = 0; j < chaptersCopy.length; j++) { |
|
if (chaptersCopy[j].position > chapter.position) { |
|
isSet = true; |
|
chapterList.splice(j, 0, chapter); |
|
} else if (chaptersCopy[j].position == chapter.position) { |
|
isSet = true; |
|
} |
|
} |
|
if (!isSet) chapterList.push(chapter); |
|
} |
|
} |
|
if (chapterList.length > 0) { |
|
chapterList[0].position = 0; |
|
this.chapters = chapterList; |
|
} else { |
|
this.chapters = false; |
|
} |
|
} |
|
Media.prototype.initInserts = function Media_initInserts(inserts) { |
|
var insertsObj = {}; |
|
for (var i in inserts) { |
|
var medias = []; |
|
if (inserts[i].length) { |
|
for (var cpt = 0; cpt < inserts[i].length; cpt++) { |
|
medias.push(new Media(this.selfName, inserts[i][cpt], true)); |
|
} |
|
} else { |
|
medias.push(new Media(this.selfName, inserts[i], true)); |
|
} |
|
if ((i === '0') || (i === 0) || (i == this.TIME_START)) { |
|
if (isDefined(insertsObj[this.TIME_START])) { |
|
insertsObj = insertsObj[this.TIME_START].concat(medias); |
|
} else { |
|
insertsObj[this.TIME_START] = medias; |
|
} |
|
} else if ((i == this.duration) || (i == this.TIME_END)) { |
|
if (isDefined(insertsObj[this.TIME_END])) { |
|
insertsObj = insertsObj[this.TIME_END].concat(medias); |
|
} else { |
|
insertsObj[this.TIME_END] = medias; |
|
} |
|
} else if (i == this.TIME_MID) { |
|
if (isDefined(insertsObj[this.TIME_MID])) { |
|
insertsObj = insertsObj[this.TIME_MID].concat(medias); |
|
} else { |
|
insertsObj[this.TIME_MID] = medias; |
|
} |
|
} else if (typeof i === 'number') { |
|
if (isDefined(insertsObj[i])) { |
|
insertsObj = insertsObj[i].concat(medias); |
|
} else { |
|
insertsObj[i] = medias; |
|
} |
|
} else if (typeof i === 'string' && isFinite(i)) { |
|
i = parseInt(i, 10); |
|
if (isDefined(insertsObj[i])) { |
|
insertsObj = insertsObj[i].concat(medias); |
|
} else { |
|
insertsObj[i] = medias; |
|
} |
|
} |
|
} |
|
this.inserts = insertsObj; |
|
} |
|
Media.prototype.setReprisePosition = function Media_setReprisePosition(position) { |
|
if (position !== false && position > this.timeBeforeInsert) this.timeBeforeInsert = position; |
|
this.reprisePosition = isDefined(position) ? position : false; |
|
} |
|
Media.prototype.getLastInserts = function Media_getLastInserts(position) { |
|
if (this.inserts) { |
|
var medias = false; |
|
for (var time in this.inserts) { |
|
var timeLastInsert = false; |
|
if (isFinite(time)) { |
|
var timeToString = parseInt(time, 10); |
|
var diff = position - timeToString; |
|
if (timeToString > this.timeBeforeInsert && diff >= 0 && (diff < timeLastInsert || !timeLastInsert)) { |
|
timeLastInsert = timeToString; |
|
medias = this.inserts[time]; |
|
} |
|
} |
|
} |
|
return medias; |
|
} else { |
|
return false; |
|
} |
|
} |
|
Media.prototype.getAllInserts = function Media_getAllInserts() { |
|
if (this.inserts) { |
|
var inserts = new Array(); |
|
for (var i in this.inserts) { |
|
var insertsByTime = this.inserts[i]; |
|
for (var j in insertsByTime) { |
|
inserts.push(insertsByTime[j]); |
|
} |
|
} |
|
return inserts; |
|
} else return false; |
|
} |
|
Media.prototype.getInsertsStart = function Media_getInsertsStart() { |
|
if (this.inserts && this.inserts[this.TIME_START]) return this.inserts[this.TIME_START]; |
|
} |
|
Media.prototype.getInsertsEnd = function Media_getInsertsEnd() { |
|
if (this.inserts && this.inserts[this.TIME_END]) return this.inserts[this.TIME_END]; |
|
} |
|
Media.prototype.getInserts = function Media_getInserts(position) { |
|
var inserts = false; |
|
if (!this.inserts) return inserts; |
|
switch (position) { |
|
case this.TIME_START: |
|
case this.TIME_MID: |
|
case this.TIME_END: |
|
if (this.inserts[position]) inserts = this.inserts[position]; |
|
break; |
|
case undefined: |
|
inserts = new Array(); |
|
for (var i in this.inserts) { |
|
var insertsByTime = this.inserts[i]; |
|
for (var j in insertsByTime) { |
|
inserts.push(insertsByTime[j]); |
|
} |
|
} |
|
break; |
|
default: |
|
for (var time in this.inserts) { |
|
var timeLastInsert = false; |
|
if (isFinite(time)) { |
|
var timeToString = parseInt(time, 10); |
|
var diff = position - timeToString; |
|
if (timeToString > this.timeBeforeInsert && diff >= 0 && (diff < timeLastInsert || !timeLastInsert)) { |
|
timeLastInsert = timeToString; |
|
inserts = this.inserts[time]; |
|
} |
|
} |
|
} |
|
} |
|
return inserts; |
|
} |
|
Media.prototype.getInsertsMid = function Media_getInsertsMid() { |
|
if (this.inserts && this.inserts[this.TIME_MID]) return this.inserts[this.TIME_MID]; |
|
} |
|
Media.prototype.setAsset = function Media_setAsset(asset) { |
|
this.asset = asset; |
|
if (!this.name) this.name = this.asset.asset_name; |
|
if (!this.synopsis) this.synopsis = this.asset.asset_description; |
|
} |
|
Media.prototype.setType = function Media_setType(target) { |
|
if (target) { |
|
if (typeof (this.target) == "object") { |
|
this.type = this.TYPE_ASSET; |
|
} else if (typeof (this.target) == "string") { |
|
if (target.toLowerCase().match(/^http(s)?:\/\//)) { |
|
this.type = this.TYPE_HTTP; |
|
} else if (target.toLowerCase().indexOf("rtsp://") == 0) { |
|
this.type = this.TYPE_RTSP; |
|
} else { |
|
this.type = this.TYPE_ID; |
|
} |
|
} else { |
|
this.type = this.TYPE_ID; |
|
} |
|
} |
|
return this.type; |
|
} |
|
Media.prototype.setRtspStreamList = function Media_setRtspStreamList(rtspStreamList) { |
|
this.rtspStreamList = rtspStreamList; |
|
this.rtspStreamListIndex = 0; |
|
this.noMoreStreams = false; |
|
this.target = this.getRtspStream(); |
|
this.setType(this.target); |
|
} |
|
Media.prototype.getRtspStream = function Media_getRtspStream(next) { |
|
if (!isDefined(this.rtspStreamList) || !this.rtspStreamList.length) { |
|
this.noMoreStreams = true; |
|
return false; |
|
} |
|
stream = this.rtspStreamList[this.rtspStreamListIndex]; |
|
if (next) { |
|
if (this.rtspStreamListIndex + 1 < this.rtspStreamList.length) { |
|
this.rtspStreamListIndex++; |
|
stream = this.rtspStreamList[this.rtspStreamListIndex]; |
|
} else { |
|
this.noMoreStreams = true; |
|
stream = false; |
|
} |
|
} |
|
return (stream ? stream : (this.rtspStreamListIndex < this.rtspStreamList.length - 1 ? this.getRtspStream(true) : false)); |
|
} |
|
Media.prototype._setTrace = function Media__setTrace(action) { |
|
if (!isDefined(this.position)) return false; |
|
var dateOffset = (this.traces.length ? new Date().getTime() - this.traces[0][0] : new Date().getTime()); |
|
this.traces.push([dateOffset, action, this.position]); |
|
} |
|
Media.prototype.getStreamer = function Media_getStreamer() { |
|
var streamer = false; |
|
if (typeof this.target === "string") { |
|
var url = this.target; |
|
var tmp = false; |
|
if (url && (tmp = url.match(/^[a-z]*:\/\/([^\/]*)/))) streamer = tmp[1]; |
|
} |
|
return streamer; |
|
} |
|
Media.prototype.getStreamName = function Media_getStreamName() { |
|
var fileName = ""; |
|
if (typeof this.target === "string") { |
|
fileName = this.target.substring(this.target.lastIndexOf("/") + 1); |
|
if (fileName && fileName.indexOf("?")) fileName = fileName.substring(0, fileName.indexOf("?")); |
|
} |
|
return fileName; |
|
} |
|
Media.prototype.setStats = function Media_setStats(stats) { |
|
if (this.stats && (this.stats.packetCount || this.stats.errorCount)) this.oldStats = this.stats; |
|
this.stats = stats; |
|
} |
|
Media.prototype.getStats = function Media_getStats() { |
|
var stats = this.stats; |
|
if (stats && !stats.packetCount && !stats.errorCount && this.oldStats && (this.oldStats.packetCount || this.oldStats.errorCount)) stats = this.oldStats; |
|
return stats; |
|
} |
|
Media.prototype.setStatus = function Media_setStatus(status) { |
|
this.status = status; |
|
return this.status; |
|
} |
|
Media.prototype.setRightsReloaded = function Media_setRightsReloaded() { |
|
if (this.rightsReloaded) return false; |
|
else { |
|
this.rightsReloaded = true; |
|
return true; |
|
} |
|
} |
|
Media.prototype.setVisuConfirmed = function Media_setVisuConfirmed() { |
|
if (this.visuConfirmed) return false; |
|
else { |
|
this.visuConfirmed = true; |
|
return true; |
|
} |
|
} |
|
Media.prototype.reset = function Media_reset() { |
|
this.started = false; |
|
this.ended = false; |
|
this.noMoreStreams = false; |
|
this.pauseTried = false; |
|
this.oldStats = null; |
|
this.oldPosition = null; |
|
} |
|
Media.prototype.setPosition = function Media_setPosition(position) { |
|
if (this.position && position) { |
|
this.oldPosition = this.position; |
|
} |
|
this.position = position; |
|
} |
|
Media.prototype.setEnded = function Media_setEnded() { |
|
this.ended = true; |
|
} |
|
Media.prototype.setStopped = function Media_setStopped() { |
|
this.stopped = true; |
|
} |
|
Media.prototype.nbInserts = function Media_nbInserts() { |
|
var nbInserts = 0; |
|
for (var i in this.inserts) { |
|
nbInserts += this.inserts[i].length; |
|
} |
|
return nbInserts; |
|
} |