From b92b1fc101a5a5ba8bb212e7bebc31ccc94f8dc1 Mon Sep 17 00:00:00 2001 From: thlo Date: Wed, 26 Dec 2012 11:08:33 +0100 Subject: Initial Widget Version --- smarttv-client/Javascript/Audio.js | 31 + smarttv-client/Javascript/CVS/Entries | 13 + smarttv-client/Javascript/Config.js | 227 ++++++++ smarttv-client/Javascript/Data.js | 155 +++++ smarttv-client/Javascript/Display.js | 757 ++++++++++++++++++++++++ smarttv-client/Javascript/Main.js | 1029 +++++++++++++++++++++++++++++++++ smarttv-client/Javascript/Network.js | 25 + smarttv-client/Javascript/Options.js | 66 +++ smarttv-client/Javascript/Player.js | 350 +++++++++++ smarttv-client/Javascript/Server.js | 141 +++++ 10 files changed, 2794 insertions(+) create mode 100755 smarttv-client/Javascript/Audio.js create mode 100755 smarttv-client/Javascript/CVS/Entries create mode 100755 smarttv-client/Javascript/Config.js create mode 100755 smarttv-client/Javascript/Data.js create mode 100755 smarttv-client/Javascript/Display.js create mode 100755 smarttv-client/Javascript/Main.js create mode 100755 smarttv-client/Javascript/Network.js create mode 100755 smarttv-client/Javascript/Options.js create mode 100755 smarttv-client/Javascript/Player.js create mode 100755 smarttv-client/Javascript/Server.js (limited to 'smarttv-client/Javascript') diff --git a/smarttv-client/Javascript/Audio.js b/smarttv-client/Javascript/Audio.js new file mode 100755 index 0000000..6046c37 --- /dev/null +++ b/smarttv-client/Javascript/Audio.js @@ -0,0 +1,31 @@ +var Audio = +{ + plugin : null +}; + +Audio.init = function() +{ + var success = true; + + this.plugin = document.getElementById("pluginAudio"); + + if (!this.plugin) + { + success = false; + } + + return success; +}; + +Audio.setRelativeVolume = function(delta) +{ + this.plugin.SetVolumeWithKey(delta); + Display.setVolume( this.getVolume() ); + +}; + +Audio.getVolume = function() +{ + alert("Volume : " + this.plugin.GetVolume()); + return this.plugin.GetVolume(); +}; diff --git a/smarttv-client/Javascript/CVS/Entries b/smarttv-client/Javascript/CVS/Entries new file mode 100755 index 0000000..0ce6906 --- /dev/null +++ b/smarttv-client/Javascript/CVS/Entries @@ -0,0 +1,13 @@ +/Audio.js/1.2/Sun Oct 21 11:06:19 2012// +/Comm.js/-1.4/Wed Dec 12 19:36:09 2012// +/Config.js/1.2/Thu Dec 20 20:52:57 2012// +/Data.js/1.8/Thu Dec 13 18:51:43 2012// +/Display.js/1.33/Thu Dec 20 19:34:59 2012// +/HandlePages.js/-1.1/Sat Oct 6 06:18:38 2012// +/Main.js/1.38/Thu Dec 20 20:53:18 2012// +/Network.js/1.2/Tue Oct 23 18:04:28 2012// +/Options.js/1.2/Sun Dec 16 13:29:28 2012// +/Player.js/1.33/Thu Dec 20 20:42:11 2012// +/Server.js/1.13/Thu Dec 13 18:51:44 2012// +/debug.js/-1.2/Fri Oct 19 19:26:18 2012// +/dlna.js/-1.1/Wed Oct 17 13:56:23 2012// diff --git a/smarttv-client/Javascript/Config.js b/smarttv-client/Javascript/Config.js new file mode 100755 index 0000000..b0742a4 --- /dev/null +++ b/smarttv-client/Javascript/Config.js @@ -0,0 +1,227 @@ +var Config = { + cfgFileName : curWidget.id + "/config.dta", + XHRObj : null, + xmlDocument : null, + serverUrl : "", // Will become the main URL for contacting the server + serverAddr : "192.168.1.122:8000", + format :"has", + tgtBufferBitrate : 6000, // kbps + totalBufferDuration : 30, // sec + initialBuffer : 10, // in percent + pendingBuffer: 40, // in percent + initialTimeOut: 3, // sec + skipDuration : 30, // sec + noLiveChannels : 30, + firstLaunch : false +}; + + +/* + * Check for First launch + * Launch Config Menu + * Write File in Confi Menu + * Come back here, read the file and continue + */ + + +Config.init = function () { + var fileSystemObj = new FileSystem(); + + if (fileSystemObj.isValidCommonPath(curWidget.id) == 0){ + Display.showPopup ("First Launch of the Widget --> Launching Config Menu"); + alert("First Launch of the Widget"); + // should switch to the config screen here + var res = fileSystemObj.createCommonDir(curWidget.id); + if (res == true) { + Config.firstLaunch = true; + +// Config.writeContext("192.168.1.122:8000"); + Main.changeState(4); + return; + } + else { + Display.showPopup ("ERROR: Cannot create widget folder"); + } + return; + } + + else { + Config.readContext(); + } + + Config.fetchConfig(); +}; + +Config.fetchConfig = function () { + if (this.XHRObj == null) { + this.XHRObj = new XMLHttpRequest(); + } + + if (this.XHRObj) { + + this.XHRObj.onreadystatechange = function() { + if (Config.XHRObj.readyState == 4) { + Config.processConfig(); + } + }; + + this.XHRObj.open("GET", this.serverUrl + "/widget.conf", true); + this.XHRObj.send(null); + } +}; + +Config.writeContext = function (addr) { + var fileSystemObj = new FileSystem(); + + var fd = fileSystemObj.openCommonFile(Config.cfgFileName,"w"); + + fd.writeLine('serverAddr ' + addr); // SHould be overwritten by Options menue + fileSystemObj.closeCommonFile(fd); +}; + +Config.updateContext = function (addr) { + var fileSystemObj = new FileSystem(); + + var fd = fileSystemObj.openCommonFile(Config.cfgFileName,"w"); + + fd.writeLine('serverAddr ' + addr); // SHould be overwritten by Options menue + fileSystemObj.closeCommonFile(fd); + + Config.serverAddr = addr; + Config.serverUrl = "http://" + Config.serverAddr; +}; + +Config.readContext = function () { + var fileSystemObj = new FileSystem(); + +// Display.showPopup ("Reading Config file for curWidget.id= " + curWidget.id); + + try { + var fd = fileSystemObj.openCommonFile(Config.cfgFileName, "r"); + + var line = ""; + + while (line = fd.readLine()) { + var avp = line.split(" "); +// Display.showPopup ("Reading Config: attr= " + avp[0] + " val= " + avp[1]); + if (avp.length > 1) { + Config.serverAddr = avp[1]; + Config.serverUrl = "http://" + Config.serverAddr; + } + else { + Display.showPopup ("WARNING: Error in Config File"); + } + } + fileSystemObj.closeCommonFile(fd); + } + catch (e) { + var res = fileSystemObj.createCommonDir(curWidget.id); + if (res == true) { + Display.showPopup ("*** Read Error and Widget Folder successfully created ***"); + alert("-------------- Error: res = true ------------------------"); + } + else { + Display.showPopup ("*** Read Error and Widget Folder creation failed ***"); + alert("-------------- Error: res = false ------------------------"); + } + + Config.firstLaunch = true; + Main.changeState(4); + } +}; + + +Config.getXmlValue = function (itm) { + var val = this.xmlDocument.getElementsByTagName(itm); + var res = 0; + try { + res = val[0].firstChild.data; + } + catch (e) { + Main.log("parsing widget.conf: Item= " + itm + " not found" + e); + alert ("parsing widget.conf: Item= " + itm + " not found e= " + e); + } + return res; + +}; + +Config.getXmlString = function (itm) { + var val = this.xmlDocument.getElementsByTagName(itm); + + var res = ""; + try { + res = val[0].firstChild.data; + } + catch (e) { + Main.log("parsing widget.conf: Item= " + itm + " not found" + e); + alert ("parsing widget.conf: Item= " + itm + " not found e= " + e); + }; + + return res; +}; + +Config.processConfig = function () { + if (this.XHRObj.status != 200) { + alert ("Config Server Error"); + Display.showPopup("Config Server Error " + this.XHRObj.status); + Main.log("Config Server Error " + this.XHRObj.status); + } + else { + var xmlResponse = this.XHRObj.responseXML; + if (xmlResponse == null) { + alert ("xml error"); + Display.showPopup("Error in XML Config File"); + return; + } + this.xmlDocument = xmlResponse.documentElement; + if (!this.xmlDocument ) { + alert("Failed to get valid Config XML"); + Display.showPopup("Failed to get valid Config XML"); + return; + } + else { + alert ("Paring config XML now"); + this.format = Config.getXmlString("format"); + var res = Config.getXmlValue("tgtBufferBitrate"); + if (res != 0) + this.tgtBufferBitrate = 1.0 * res; + res = Config.getXmlValue("totalBufferDuration"); + if (res != 0) this.totalBufferDuration = 1.0 * res; + + res= Config.getXmlValue("initialBuffer"); + if (res != 0) this.initialBuffer = 1.0 * res; + + res = Config.getXmlValue("pendingBuffer"); + if (res != 0) this.pendingBuffer = 1.0 * res; + + res = Config.getXmlValue("skipDuration"); + if (res != 0) this.skipDuration= 1.0 * res; + + res = Config.getXmlValue("initialTimeOut"); + if (res != 0) this.initialTimeOut = 1.0 * res; + + res = Config.getXmlValue("liveChannels"); + if (res != 0) noLiveChannels = res; + + alert("**** Config ****"); + alert("serverUrl= " + Config.serverUrl); + alert("format= " + Config.format); + alert("tgtBufferBitrate= " + Config.tgtBufferBitrate); + alert("totalBufferDuration= " + Config.totalBufferDuration); + alert("initialBuffer= " + Config.initialBuffer); + alert("pendingBuffer= " + Config.pendingBuffer); + alert("skipDuration= " + Config.skipDuration); + alert("initialTimeOut= " + Config.initialTimeOut); + alert("**** /Config ****"); + }; + + }; + + Main.init(); +}; + +// This function cleans up after un-installation +Config.reset = function () { + var fileSystemObj = new FileSystem(); + fileSystemObj.deleteCommonFile(curWidget.id + "/config.dta"); +}; diff --git a/smarttv-client/Javascript/Data.js b/smarttv-client/Javascript/Data.js new file mode 100755 index 0000000..a2de13f --- /dev/null +++ b/smarttv-client/Javascript/Data.js @@ -0,0 +1,155 @@ +var Data = +{ + assets : new Item, + folderList : [], +}; + +Data.reset = function() { + this.assets = null; + this.assets = new Item; + + this.folderList = []; + + this.folderList.push({item : this.assets, id: 0}); +}; + +Data.completed= function(sort) { + if (sort == true) + this.assets.sortPayload(); + + this.folderList.push({item : this.assets, id: 0}); + alert ("Data.completed()= " +this.folderList.length); + +}; + +Data.selectFolder = function (idx) { + this.folderList.push({item : this.getCurrentItem().childs[idx], id: idx}); +}; + +Data.isRootFolder = function() { + if (this.folderList.length == 1) + return true; + else + return false; +}; + +Data.folderUp = function () { + itm = this.folderList.pop(); + return itm.id; +}; + +Data.addItem = function(t_list, pyld) { + this.assets.addChild(t_list, pyld, 0); +}; + +Data.dumpFolderStruct = function(){ + alert("---------- dumpFolderStruct ------------"); + this.assets.print(0); + alert("---------- dumpFolderStruct Done -------"); +}; + +Data.getCurrentItem = function () { + return this.folderList[this.folderList.length-1].item; +}; + +Data.getVideoCount = function() +{ + return this.folderList[this.folderList.length-1].item.childs.length; +}; + + +//----------------------------------------- +function Item() { + this.title = "root"; + this.isFolder = true; + this.childs = []; + this.payload = ""; // only set, if (isFolder == false) +} + +Item.prototype.isFolder = function() { + return this.isFolder; +}; + +Item.prototype.getTitle = function () { + return this.title; +}; + +Item.prototype.getPayload = function () { + if (this.isFolder == true) { + alert("WARNING: getting payload on a folder title=" +this.title); + } + return this.payload; +}; + +Item.prototype.getItem = function (title) { + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].title == title) { + return this.childs[i]; + } + } + return 0; +}; + +Item.prototype.addChild = function (key, pyld, level) { + if (key.length == 1) { + var folder = new Item; +// folder.title = pyld.startstr + " - " + key; + folder.title = key[0]; + folder.payload = pyld; + folder.isFolder = false; + this.childs.push(folder); +// this.titles.push({title: pyld.startstr + " - " + key , pyld : pyld}); + } + else { + if (level > 10) { + alert(" too many levels"); + return; + } + var t = key.shift(); + var found = false; + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].title == t) { + this.childs[i].addChild(key, pyld, level +1); + found = true; + break; + } + } + if (found == false) { + var folder = new Item; + folder.title = t; + folder.addChild(key, pyld, level+1); + this.childs.push(folder); + } + } +}; + +Item.prototype.print = function(level) { + var prefix= ""; + for (var i = 0; i < level; i++) + prefix += " "; + + for (var i = 0; i < this.childs.length; i++) { + alert(prefix + this.childs[i].title); + if (this.childs[i].isFolder == true) { + alert(prefix+"Childs:"); + this.childs[i].print(level +1); + } + } +}; + +Item.prototype.sortPayload = function() { + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].isFolder == true) { + this.childs[i].sortPayload(); + } + } + this.childs.sort(function(a,b) { + if (a.title == b.title) { + return (b.payload.start - a.payload.start); + } + else { + return ((a.title < b.title) ? -1 : 1); + } + }); +}; + diff --git a/smarttv-client/Javascript/Display.js b/smarttv-client/Javascript/Display.js new file mode 100755 index 0000000..fa90887 --- /dev/null +++ b/smarttv-client/Javascript/Display.js @@ -0,0 +1,757 @@ +var Display = +{ + pluginTime : null, + statusDiv : null, + statusPopup : null, + bufferingElm : null, + FIRSTIDX : 0, + LASTIDX : 15, + currentWindow : 0, + + olTitle : "", + olStartStop: "", + SELECTOR : 0, + LIST : 1, + +// folderPath : new Array(), + volOlHandler : null, + progOlHandler : null, + popupOlHandler : null, + videoList : new Array() +}; + + + +Display.init = function() +{ + var success = true; + + this.statusDiv = document.getElementById("status"); + this.statusPopup = document.getElementById("statusPopup"); + + this.pluginTime = document.getElementById("pluginTime"); + this.bufferingElm = document.getElementById("bufferingBar"); + + alert("Display.init now=" + this.pluginTime.GetEpochTime()); + + this.progOlHandler = new OverlayHandler("ProgHndl"); + this.volOlHandler = new OverlayHandler("VolHndl"); + this.popupOlHandler = new OverlayHandler("PopupHndl"); + this.progOlHandler.init(Display.handlerShowProgress, Display.handlerHideProgress); + this.volOlHandler.init(Display.handlerShowVolume, Display.handlerHideVolume); + this.popupOlHandler.init(Display.handlerShowPopup, Display.handlerHidePopup); + + Display.status("Stop"); + if (!this.statusDiv) + { + success = false; + } + for (var i = 0; i <= this.LASTIDX; i++) { + var elm = document.getElementById("video"+i); + elm.style.paddingLeft = "10px"; + elm.style.paddingTop = "4px"; + elm.style.paddingBottom = "6px"; + } + + var done = false; + var i = 0; + while (done != true) { + i ++; + var elm = document.getElementById("selectItem"+i); + if (elm == null) { + done = true; + alert( " only found to selectItem"+ (i-1)); + break; + } + elm.style.paddingBottom = "3px"; + elm.style.marginTop= " 5px"; + elm.style.marginBottom= " 5px"; + elm.style.textAlign = "center"; + } + + alert("Display initialized" ); + return success; +}; + +Display.resetSelectItems = function (itm) { + var done = false; + var i = 0; + while (done != true) { + i ++; + var elm = document.getElementById("selectItem"+i); + if (elm == null) { + done = true; + alert( " only found to selectItem"+ (i-1)); + break; + } + Display.unselectItem(elm); + } + Display.selectItem(document.getElementById("selectItem"+itm)); +}; + +Display.resetVideoList = function () { + var done = false; + var i = 0; + while (done != true) { + i ++; + var elm = document.getElementById("video"+i); + if (elm == null) { + done = true; + break; + } + Display.unselectItem(elm); + widgetAPI.putInnerHTML(elm, ""); + } + +}; + +Display.setOlTitle = function (title) { + this.olTitle = title; + var elm = document.getElementById("olTitle"); + widgetAPI.putInnerHTML(elm, Display.olTitle); +}; + +Display.setStartStop = function(start, stop) { + this.olStartStop = ""; + + var digi =new Date(start * 1000); + var hours=digi.getHours(); + var minutes=digi.getMinutes(); + if (minutes<=9) + minutes='0'+minutes; + this.olStartStop = hours + ":" + minutes + " - "; + + digi =new Date(stop * 1000); + hours=digi.getHours(); + minutes=digi.getMinutes(); + if (minutes<=9) + minutes='0'+minutes; + this.olStartStop = this.olStartStop + hours + ":" + minutes; + + var elm = document.getElementById("olStartStop"); + widgetAPI.putInnerHTML(elm, Display.olStartStop); +}; + +/* +//obsolete? +Display.setTotalTime = function(total) { + this.totalTime = total; +}; +*/ +/* + +// Player.OnCurrentPlayTime +Display.setTime = function(time) { + var timePercent = (100 * time) / this.totalTime; + var timeHTML = ""; + var timeHour = 0; var timeMinute = 0; var timeSecond = 0; + var totalTimeHour = 0; var totalTimeMinute = 0; + var totalTimesecond = 0; + + if(Player.state == Player.PLAYING) + { + totalTimeHour = Math.floor(this.totalTime/3600000); + timeHour = Math.floor(time/3600000); + + totalTimeMinute = Math.floor((this.totalTime%3600000)/60000); + timeMinute = Math.floor((time%3600000)/60000); + + totalTimeSecond = Math.floor((this.totalTime%60000)/1000); + timeSecond = Math.floor((time%60000)/1000); + + timeHTML = timeHour + ":"; + + if(timeMinute == 0) + timeHTML += "00:"; + else if(timeMinute <10) + timeHTML += "0" + timeMinute + ":"; + else + timeHTML += timeMinute + ":"; + + if(timeSecond == 0) + timeHTML += "00/"; + else if(timeSecond <10) + timeHTML += "0" + timeSecond + "/"; + else + timeHTML += timeSecond + "/"; + + timeHTML += totalTimeHour + ":"; + + if(totalTimeMinute == 0) + timeHTML += "00:"; + else if(totalTimeMinute <10) + timeHTML += "0" + totalTimeMinute; + else + timeHTML += totalTimeMinute; + + if(totalTimeSecond == 0) + timeHTML += "00"; + else if(totalTimeSecond <10) + timeHTML += "0" + totalTimeSecond; + else + timeHTML += totalTimeSecond; + } + else + timeHTML = "0:00:00/0:00:00"; +}; +*/ + +Display.getHumanTimeRepresentation = function(time) { + var totalTimeHour = 0; + var totalTimeMinute = 0; + var totalTimeSecond = 0; + + totalTimeHour = Math.floor(time/3600000); + totalTimeMinute = Math.floor((time%3600000)/60000); + totalTimeSecond = Math.floor((time%60000)/1000); + + var totalTimeStr = totalTimeHour + ":"; + + if(totalTimeMinute == 0) + totalTimeStr += "00:"; + else if(totalTimeMinute <10) + totalTimeStr += "0" + totalTimeMinute + ":"; + else + totalTimeStr += totalTimeMinute + ":"; + + if(totalTimeSecond == 0) + totalTimeStr += "00"; + else if(totalTimeSecond <10) + totalTimeStr += "0" + totalTimeSecond; + else + totalTimeStr += totalTimeSecond; + + return totalTimeStr; +}; + +/* +// called by Player.OnStreamInfoReady +Display.updateTotalTime = function(time) { + Player.totalTimeStr = Display.getHumanTimeRepresentation(time); +}; +*/ + +// Player.OnCurrentPlayTime +Display.updatePlayTime = function() { +// Player.curPlayTimeStr = Display.getHumanTimeRepresentation(Player.curPlayTime); + var timeElement = document.getElementById("olTimeInfo"); + widgetAPI.putInnerHTML(timeElement, Player.curPlayTimeStr + " / " + Player.totalTimeStr); +}; + +Display.updateProgressBar = function () { + var timePercent = (Player.curPlayTime *100)/ Player.totalTime; + document.getElementById("olProgressBar").style.width = Math.round(timePercent) + "%"; +}; + +Display.updateRecBar = function (start_time, duration){ + var now = Display.pluginTime.GetEpochTime(); + + var remaining = Math.round(((start_time + duration) - now) * 100/ duration); +// alert (" remaining= " + remaining + " start= " + start_time + " dur= " + duration); + var elm = document.getElementById("olRecProgressBar"); + elm.style.display="block"; + elm.style.width = remaining + "%"; + elm.style.left = (100 - remaining) + "%"; +}; + + +Display.status = function(status) { + alert(status); + widgetAPI.putInnerHTML(this.statusDiv, status); + widgetAPI.putInnerHTML(this.statusPopup, status); +}; + +Display.showStatus = function() { + this.statusPopup.style.display="block"; +}; + +Display.hideStatus = function() { + this.statusPopup.style.display="none"; +}; + + +Display.progress = function(status) { + widgetAPI.putInnerHTML(this.statusDiv, status); +}; + + +Display.durationString = function(time) { + var timeHour = 0; + var timeMinute = 0; + var timeSecond = 0; + var res = ""; + + timeHour = Math.floor(time/3600); + timeMinute = Math.floor((time%3600)/60); + timeSecond = Math.floor(time%60); + + res = "0:"; + if (timeHour != 0) + res = timeHour + ":"; + + if(timeMinute == 0) + res += "00:"; + else if(timeMinute <10) + res += "0" + timeMinute + ":"; + else + res += timeMinute + ":"; + + if(timeSecond == 0) + res += "00"; + else if(timeSecond <10) + res += "0" + timeSecond; + else + res += timeSecond; + + return res; +}; + + +Display.handleDescription =function (selected) { + + if (Data.getCurrentItem().childs[selected].isFolder == true) { + Display.setDescription( "Dir: " +Data.getCurrentItem().childs[selected].title ); + } + else { + var itm = Data.getCurrentItem().childs[selected]; + var title = itm.title; + var prog = itm.payload.prog; + var desc = itm.payload.desc; + var length = itm.payload.dur; + + var digi = new Date(parseInt(itm.payload.start*1000)); + var mon = Display.getNumString ((digi.getMonth()+1), 2); + var day = Display.getNumString (digi.getDate(), 2); + var hour = Display.getNumString (digi.getHours(), 2); + var min = Display.getNumString (digi.getMinutes(), 2); + + var d_str =""; +// alert("handleDescription: " +Data.getCurrentItem().childs[selected].payload.desc); + var msg = ""; + if (Main.state == 1) { + // Live + var now = pluginTime.GetEpochTime(); + + d_str = hour + ":" + min; + + msg += title + "
"; + msg += ""+ prog + "
"; + msg += "
Start: " + d_str + "
"; + msg += "Duration: " + Display.durationString(length) + "h
"; + msg += "Remaining: " + Display.durationString((itm.payload.start + length - now)); + } + else { + // on-demand + d_str = mon + "/" + day + " " + hour + ":" + min; + + msg += "" + title + ""; + msg += "

" + d_str; + msg += " Duration: " + Display.durationString(length) + "h"; + } + msg += "

"+ desc; + Display.setDescription(msg); + } + +}; + +Display.getNumString =function(num, fmt) { + var res = ""; + + if (num < 10) { + for (var i = 1; i < fmt; i ++) { + res += "0"; + }; + } else if (num < 100) { + for (var i = 2; i < fmt; i ++) { + res += "0"; + }; + } + + res = res + num; + + return res; +}; + +Display.getDisplayTitle = function(item) { + var res = ""; + switch (Main.state) { + case 1: + // Live + res = item.title; + break; + case 2: + case 3: + // Recordings + if (item.isFolder == true) { +// res = "<" + Display.getNumString(item.childs.length, 3) + ">-------- " + item.title; + res = "<" + Display.getNumString(item.childs.length, 3) + ">       - " + item.title; + + } + else { + var digi = new Date(parseInt(item.payload.start*1000)); + var mon = Display.getNumString ((digi.getMonth()+1), 2); + var day = Display.getNumString (digi.getDate(), 2); + var hour = Display.getNumString (digi.getHours(), 2); + var min = Display.getNumString (digi.getMinutes(), 2); + + var d_str = mon + "/" + day + " " + hour + ":" + min; + res = d_str + " - " + item.title; + } + break; + default: + alert("ERROR: Shall be in state 1 or 2. State= " + Main.state); + break; + } + return res; +}; + +Display.setVideoList = function(selected, first) { + // + var listHTML = ""; + var first_item = selected; + if(typeof first !='undefined') { + first_item = first; + alert("Display.setVideoList first_item= " + first_item); + } + + var i=0; + alert("Display.setVideoList title= " +Data.getCurrentItem().childs[selected].title + " selected= " + selected + " first_item= " + first_item); + this.handleDescription(selected); + + for (i = 0; i <= this.LASTIDX; i++) { + if ((first_item+i) >= Data.getVideoCount()) { + listHTML = ""; + } + else { +// alert(" - title[first_item+i]= " +Data.getCurrentItem().childs[(first_item +i)].title + " i= " + i); + listHTML = Display.getDisplayTitle (Data.getCurrentItem().childs[first_item+i]); + } + this.videoList[i] = document.getElementById("video"+i); + widgetAPI.putInnerHTML(this.videoList[i], listHTML); + this.unselectItem(this.videoList[i]); + } + + this.currentWindow = (selected - first_item); + this.selectItem(this.videoList[this.currentWindow]); + + listHTML = (selected +1) + " / " + Data.getVideoCount(); + + widgetAPI.putInnerHTML(document.getElementById("videoCount"), listHTML); +}; + +Display.selectItem = function (item) { + + item.style.color = "black"; + item.style.background = "-webkit-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,1) 50%,rgba(215,222,227,1) 51%,rgba(245,247,249,1) 100%)"; + item.style.borderRadius= "3px"; + item.style["-webkit-box-shadow"] = "2px 2px 1px 2px rgba(0,0,0, 0.5)"; + // item.style.backgroundColor = "white"; + +}; + +Display.unselectItem = function (item) { + item.style.color = "white"; + item.style.backgroundColor = "transparent"; + item.style.background = "transparent"; + item.style["-webkit-box-shadow"] = ""; +}; + + +/* + * this.currentWindow: Cursor (selected item) + */ +Display.setVideoListPosition = function(position, move) +{ + var listHTML = ""; + alert ("Display.setVideoListPosition title= " +Data.getCurrentItem().childs[position].title + " move= " +move); + + this.handleDescription(position); + + listHTML = (position + 1) + " / " + Data.getVideoCount(); + widgetAPI.putInnerHTML(document.getElementById("videoCount"), listHTML); + + + if(Data.getVideoCount() < this.LASTIDX) { + for (var i = 0; i < Data.getVideoCount(); i++) + { + if(i == position) + this.selectItem(this.videoList[i]); + else + this.unselectItem(this.videoList[i]); + + } + } + else if((this.currentWindow!=this.LASTIDX && move==Main.DOWN) || (this.currentWindow!=this.FIRSTIDX && move==Main.UP)) + { + // Just move cursor + if(move == Main.DOWN) + this.currentWindow ++; + else + this.currentWindow --; + + for (var i = 0; i <= this.LASTIDX; i++) { + if(i == this.currentWindow) + this.selectItem(this.videoList[i]); + else + this.unselectItem(this.videoList[i]); + } + } + else if(this.currentWindow == this.LASTIDX && move == Main.DOWN) { + // Next Page + if(position == this.FIRSTIDX) { + // very top element selected + this.currentWindow = this.FIRSTIDX; + + for(i = 0; i <= this.LASTIDX; i++) { + listHTML = Display.getDisplayTitle (Data.getCurrentItem().childs[i]); +// listHTML = Data.getCurrentItem().childs[i].title; + widgetAPI.putInnerHTML(this.videoList[i], listHTML); + + if(i == this.currentWindow) + this.selectItem(this.videoList[i]); + else + this.unselectItem(this.videoList[i]); + } + } + else { + for(i = 0; i <= this.LASTIDX; i++) { + listHTML = Display.getDisplayTitle (Data.getCurrentItem().childs[i + position - this.currentWindow]); +// listHTML = Data.getCurrentItem().childs[i + position - this.currentWindow].title; + widgetAPI.putInnerHTML(this.videoList[i], listHTML); + } + } + } + else if(this.currentWindow == this.FIRSTIDX && move == Main.UP) { + // Previous Page + if(position == Data.getVideoCount()-1) { + // very bottom element selected + this.currentWindow = this.LASTIDX; + + for(i = 0; i <= this.LASTIDX; i++) { + listHTML = Display.getDisplayTitle (Data.getCurrentItem().childs[i + position - this.currentWindow]); +// listHTML = Data.getCurrentItem().childs[i + position - this.currentWindow].title; + widgetAPI.putInnerHTML(this.videoList[i], listHTML); + + if(i == this.currentWindow) + this.selectItem(this.videoList[i]); + else + this.unselectItem(this.videoList[i]); + } + } + else { + for(i = 0; i <= this.LASTIDX; i++) { + listHTML = Display.getDisplayTitle (Data.getCurrentItem().childs[i + position]); +// listHTML = Data.getCurrentItem().childs[i + position].title; + widgetAPI.putInnerHTML(this.videoList[i], listHTML); + } + } + } +}; + +Display.setDescription = function(description) { + var descriptionElement = document.getElementById("description"); + + widgetAPI.putInnerHTML(descriptionElement, description); +}; + +//-------------------------------------------------------- +Display.bufferUpdate = function() { + // Player.bufferState + // find buffering element and show status + this.bufferingElm.style.width= Player.bufferState+ "%"; +}; + +//-------------------------------------------------------- +Display.hide = function() +{ + document.getElementById("main").style.display="none"; +}; + +Display.show = function() +{ + // cancel ongoing overlays first + this.volOlHandler.cancel(); + this.progOlHandler.cancel(); + this.popupOlHandler.cancel(); + document.getElementById("main").style.display="block"; +}; + +//--------------------------------------------------------- +Display.setVolume = function(level) +{ + document.getElementById("volumeBar").style.width = level + "%"; + + var volumeElement = document.getElementById("volumeInfo"); + + widgetAPI.putInnerHTML(volumeElement, "     " + Audio.getVolume()); +}; + +// Called by main +Display.showVolume = function() { + this.volOlHandler.show(); +}; + +//called by handle +Display.handlerShowVolume = function() { + document.getElementById("volume").style.display="block"; +}; + + +//Called by handler +Display.handlerHideVolume = function() { + document.getElementById("volume").style.display="none"; +}; + + +//--------------------------------------------------------- +Display.showPopup = function(text) { + var oldHTML = document.getElementById("popup").innerHTML; + widgetAPI.putInnerHTML(document.getElementById("popup"), oldHTML + "
" + text); + this.popupOlHandler.show(); +}; + +Display.handlerShowPopup = function() { + document.getElementById("popup").style.display="block"; + +}; + +Display.handlerHidePopup = function() { + document.getElementById("popup").style.display="none"; + widgetAPI.putInnerHTML(document.getElementById("popup"), ""); +}; + +//--------------------------------------------------------- + +Display.showProgress = function() { + this.progOlHandler.show(); +}; + +Display.handlerHideProgress = function() { + document.getElementById("overlay").style.display="none"; +}; + +Display.handlerShowProgress = function() { + + document.getElementById("overlay").style.display="block"; + if (Player.isRecording == true) { + document.getElementById("olRecProgressBar").style.display="block"; + var now = pluginTime.GetEpochTime(); + var remaining = Math.round(((Player.startTime + Player.duration) - now) * 100/ Player.duration); + alert (" remaining= " + remaining); + var elm = document.getElementById("olRecProgressBar"); + elm.style.display="block"; + elm.style.width = remaining + "%"; + elm.style.left = (100 - remaining) + "%"; + } + else + document.getElementById("olRecProgressBar").style.display="none"; + + var timePercent = (Player.curPlayTime *100)/ Player.totalTime; + + alert("show OL Progress timePercent= " + timePercent); + + document.getElementById("olProgressBar").style.width = timePercent + "%"; + + var timeElement = document.getElementById("olTimeInfo"); + widgetAPI.putInnerHTML(timeElement, Player.curPlayTimeStr + " / " + Player.totalTimeStr); + + var nowElement = document.getElementById("olNow"); + var Digital=new Date(); + var hours=Digital.getHours(); + var minutes=Digital.getMinutes(); + if (minutes<=9) + minutes='0'+minutes; + widgetAPI.putInnerHTML(nowElement, hours + ':' + minutes); +}; + + + +//---------------------------------------- +function OverlayHandler (n) { + this.pluginTime = null; + this.active = false; + this.startTime = 0; + this.hideTime = 0; + this.olDelay = 3000; // in millis + this.timeoutObj = null; + + this.handlerName = n; // readable name for debugging + this.showCallback = null; // callback, which shows the element + this.hideCallback = null; // callback, which hides the element +}; + +OverlayHandler.prototype.init = function(showcb, hidecb) { + var success = true; + this.showCallback = showcb; + this.hideCallback = hidecb; + this.pluginTime = document.getElementById("pluginTime"); + if (!this.pluginTime) { + alert(this.handlerName + " cannot aquire time plugin : " + success); + success = false; + } +// alert(this.handlerName + " is initialized"); + return success; +}; + +OverlayHandler.prototype.checkHideCallback = function () { + var pluginTime = document.getElementById("pluginTime"); + var now = pluginTime.GetEpochTime(); +// alert(that.handlerName + "checkHideCallback: now= " + now + " hideTime= " + that.hideTime + " delta= " + (now - that.hideTime)); + if (now >= this.hideTime) { +// alert(this.handlerName + "hiding " + this.handlerName + " howDur: act= " + (now - this.startTime) + " int= " + (this.hideTime-this.startTime)); + + this.olDelay = 3000; + if (this.hideCallback) { + this.hideCallback(); + } + else + alert(this.handlerName + ": No hideCallback defined - ignoring " ); + + this.active = false; + return; + } + var delay = (this.hideTime - now) * 1000; +// alert(this.handlerName + "checkHideCallback: new timeout= " +delay); + + // pass an anonymous function + var self = this; + this.timeoutObj = window.setTimeout(function() {self.checkHideCallback(); }, delay); +}; + +OverlayHandler.prototype.show = function() { + if (!this.active ) { + this.startTime = this.pluginTime.GetEpochTime(); + this.hideTime = this.startTime + (this.olDelay / 1000); + +// alert(this.handlerName + " showing " + this.handlerName + " from= " + this.startTime + " to at least= " + this.hideTime); + if (this.showCallback) { + this.showCallback(); + + var self = this; + this.timeoutObj = window.setTimeout(function() {self.checkHideCallback();}, this.olDelay); + this.active = true; + } + else + alert(this.handlerName + ": No showCallback defined - ignoring " ); + } + else { +// alert(this.handlerName + " extending showtime for " + this.handlerName + " for another " + (this.olDelay /1000)+ "sec"); + this.hideTime = this.pluginTime.GetEpochTime() + (this.olDelay /1000); + } +}; + + +OverlayHandler.prototype.cancel = function () { + if (!this.active) + return; + +// alert("cancel for handler " + this.handlerName); + if (this.hideCallback) { + this.hideCallback(); + } + else + alert(this.handlerName + ": No hideCallback defined - ignoring " ); + + this.active = false; + window.clearTimeout(this.timeoutObj); +}; \ No newline at end of file diff --git a/smarttv-client/Javascript/Main.js b/smarttv-client/Javascript/Main.js new file mode 100755 index 0000000..ef92172 --- /dev/null +++ b/smarttv-client/Javascript/Main.js @@ -0,0 +1,1029 @@ +var widgetAPI = new Common.API.Widget(); +var tvKey = new Common.API.TVKeyValue(); + +var custom = window.deviceapis.customdevice || {}; + + +/* + * TODO: + * Resume + * Audio Track Select + * Screensaver (using setOnScreenSaver() from common modules) + * VDR Status on main screne + */ + + +var Main = { + state : 0, // selectScreen + selectedVideo : 0, + olTimeout : 3000, + mode : 0, + mute : 0, + + + UP : 0, + DOWN : 1, + + WINDOW : 0, + FULLSCREEN : 1, + + NMUTE : 0, + YMUTE : 1, + + defKeyHndl : null, + selectMenuKeyHndl : null, + playStateKeyHndl : null, + livePlayStateKeyHndl : null, + menuKeyHndl : null +}; + +Main.onLoad = function() { + +// Config.init("http://192.168.1.122:8000/widget.conf"); + Network.init(); + Display.init(); + + this.defKeyHndl = new cDefaulKeyHndl; + this.playStateKeyHndl = new cPlayStateKeyHndl(this.defKeyHndl); + this.livePlayStateKeyHndl = new cLivePlayStateKeyHndl(this.defKeyHndl); + this.menuKeyHndl = new cMenuKeyHndl(this.defKeyHndl); + this.selectMenuKeyHndl = new cSelectMenuKeyHndl(this.defKeyHndl); + + alert (" created KeyHandlers"); + + Config.init(); +}; + +// Called by Config, when done +Main.init = function () { + alert("Main.init()"); + if ( Player.init() && Audio.init() && Server.init() ) { + Display.setVolume( Audio.getVolume() ); + + // Start retrieving data from server + Server.dataReceivedCallback = function() + { + /* Use video information when it has arrived */ + alert("Server.dataReceivedCallback"); + Display.setVideoList(Main.selectedVideo); + + Display.show(); + }; + + // Enable key event processing + this.enableKeys(); + + Display.selectItem(document.getElementById("selectItem1")); + + document.getElementById("splashScreen").style.display="none"; + + widgetAPI.sendReadyEvent(); + } + else { + alert("Failed to initialise"); + } + +}; + +Main.log = function (msg) { + var XHRObj = new XMLHttpRequest(); + XHRObj.open("POST", Config.serverUrl + "/log", true); + XHRObj.send("CLOG: " + msg); +}; + +Main.onUnload = function() +{ + Player.deinit(); +}; + +Main.changeState = function (state) { + alert("change state: new state= " + state); + var old_state = this.state; + this.state = state; + + switch (this.state) { + case 0: + Main.selectMenuKeyHndl.select = old_state; + alert ("old Select= " + Main.selectMenuKeyHndl.select); + Display.resetSelectItems(Main.selectMenuKeyHndl.select); + + document.getElementById("selectScreen").style.display="block"; + Display.hide(); + Display.resetVideoList(); + break; + case 1: + document.getElementById("selectScreen").style.display="none"; + Display.show(); + Data.reset (); + Main.liveSelected(); + break; + case 2: + document.getElementById("selectScreen").style.display="none"; + Display.show(); + Data.reset (); + Main.recordingsSelected(); + break; + case 3: + document.getElementById("selectScreen").style.display="none"; + Display.show(); + Data.reset (); + Main.mediaSelected(); + break; + case 4: + // Options + Options.init(); + document.getElementById("selectScreen").style.display="none"; + document.getElementById("optionsScreen").style.display="block"; + Main.optionsSelected(); + break; + + } +}; + +Main.recordingsSelected = function() { + Player.stopCallback = function() { + // + var msg = "devid:" + Network.getMac() + "\n"; + msg += "title:" + Data.getCurrentItem().childs[Main.selectedVideo].title + "\n"; + msg += "start:" +Data.getCurrentItem().childs[Main.selectedVideo].payload.start + "\n"; + msg += "resume:"+ (Player.curPlayTime/1000) + "\n" ; + + var XHRObj = new XMLHttpRequest(); + XHRObj.open("POST", Config.serverUrl + "/resume", true); + XHRObj.send(msg); + + Display.show(); + }; + Player.isLive = false; + Server.setSort(true); + if (Config.format == "") { + Server.fetchVideoList(Config.serverUrl + "/recordings.xml?model=samsung"); /* Request video information from server */ + alert("fetchVideoList from: " + Config.serverUrl + "/recordings.xml?model=samsung"); + } + else { + Main.log("Using format " + Config.format); + if (Config.format == "") + Server.fetchVideoList(Config.serverUrl + "/recordings.xml?model=samsung&has4hd=false"); /* Request video information from server */ + else + Server.fetchVideoList(Config.serverUrl + "/recordings.xml?model=samsung&has4hd=false&type="+Config.format); /* Request video information from server */ + } +}; + +Main.serverError = function(errorcode) { + if (Server.retries == 0) { + switch (this.state) { + case 1: // live + Server.fetchVideoList( Config.serverUrl + "/channels.xml?mode=nodesc"); /* Request video information from server */ + break; + } + } +}; + +Main.liveSelected = function() { + Server.retries = 0; + Player.stopCallback = function() { + }; + Player.isLive = true; + Server.setSort(false); + Server.errorCallback = Main.serverError; + Server.fetchVideoList(Config.serverUrl + "/channels.xml"); /* Request video information from server */ +}; + +Main.mediaSelected = function() { + Player.stopCallback = function() { + // + Display.show(); + }; + Player.isLive = false; + Server.setSort(true); + Server.fetchVideoList(Config.serverUrl + "/media.xml"); /* Request video information from server */ +}; + +Main.optionsSelected = function() { + alert ("Main.optionsSelected"); +}; + +Main.enableKeys = function() +{ + document.getElementById("anchor").focus(); +}; + +Main.keyDown = function() { + switch (this.state) { + case 0: + // selectView + this.selectMenuKeyHndl.handleKeyDown(); + break; + case 1: + // Live + alert("Live - Main.keyDown PlayerState= " + Player.getState()); + if(Player.getState() == Player.STOPPED) { + // Menu Key + this.menuKeyHndl.handleKeyDown(); + } + else { + // Live State Keys + this.livePlayStateKeyHndl.handleKeyDown(); + }; + + break; + case 2: + case 3: + // recordings + alert("Recordings - Main.keyDown PlayerState= " + Player.getState()); + if(Player.getState() == Player.STOPPED) { + // Menu Key + this.menuKeyHndl.handleKeyDown(); + } + else { + // Play State Keys + this.playStateKeyHndl.handleKeyDown(); + }; + + break; + case 4: + alert ("ERROR: Wrong State"); + break; + }; +}; + +Main.playItem = function (url) { + alert(Main.state + " playItem for " +Data.getCurrentItem().childs[Main.selectedVideo].payload.link); + var start_time = Data.getCurrentItem().childs[Main.selectedVideo].payload.start; + var duration = Data.getCurrentItem().childs[Main.selectedVideo].payload.dur; + var now = Display.pluginTime.GetEpochTime(); + document.getElementById("olRecProgressBar").style.display="none"; + + switch (this.state) { + case 1: + // Live + Display.setOlTitle(Data.getCurrentItem().childs[Main.selectedVideo].payload.prog); + Display.setStartStop (start_time, (start_time + duration)); + Player.isLive = true; + Player.bufferState = 0; + Player.isRecording = false; + Player.totalTime = Data.getCurrentItem().childs[Main.selectedVideo].payload.dur * 1000; +// Display.updateTotalTime(Player.totalTime); + var digi = new Date((Data.getCurrentItem().childs[Main.selectedVideo].payload.start*1000)); + alert (" Date(): StartTime= " + digi.getHours() + ":" + digi.getMinutes() + ":" + digi.getSeconds()); +// Player.cptOffset = (now - Data.getCurrentItem().childs[Main.selectedVideo].payload.start) * 1000; + Player.setCurrentPlayTimeOffset((now - Data.getCurrentItem().childs[Main.selectedVideo].payload.start) * 1000); + Player.OnCurrentPlayTime(0); + alert ("Live now= " + now + " StartTime= " + Data.getCurrentItem().childs[Main.selectedVideo].payload.start + " offset= " +Player.cptOffset ); + alert("Live Content= " + Data.getCurrentItem().childs[Main.selectedVideo].title + " dur= " + Data.getCurrentItem().childs[Main.selectedVideo].payload.dur); + break; + case 2: + case 3: + Player.setCurrentPlayTimeOffset(0); +// Player.cptOffset = 0; + Player.isLive = false; + Player.isRecording = false; + alert(" playItem: now= " + now + " start_time= " + start_time + " dur= " + duration + " (Start + Dur - now)= " + ((start_time + duration) -now)); + if ((now - (start_time + duration)) < 0) { + // still recording + alert("*** Still Recording! ***"); + Player.isRecording = true; + Player.startTime = start_time; + Player.duration = duration; + Player.totalTime = Data.getCurrentItem().childs[Main.selectedVideo].payload.dur * 1000; + document.getElementById("olRecProgressBar").style.display="block"; + + Display.updateRecBar(start_time, duration); + } + else { + document.getElementById("olRecProgressBar").display="none"; + } + Display.setOlTitle(Data.getCurrentItem().childs[Main.selectedVideo].title); + Display.olStartStop = ""; + break; + }; + + Player.setVideoURL( Data.getCurrentItem().childs[Main.selectedVideo].payload.link); + Player.playVideo(); +}; + +Main.selectPageUp = function(up) { + if (this.selectedVideo == 0) { + Main.changeState(0); + return; + }; + + this.selectedVideo = (this.selectedVideo - (Display.LASTIDX + 1)); + if (this.selectedVideo < 0) { + this.selectedVideo = 0; + } + + var first_item = this.selectedVideo - Display.currentWindow; + if (first_item < 0 ) + first_item = 0; + alert("selectPageUp: this.selectedVideo= " + this.selectedVideo + " first_item= " + first_item); + + Display.setVideoList(this.selectedVideo, first_item); +}; + +Main.selectPageDown = function(down) { + this.selectedVideo = (this.selectedVideo + Display.LASTIDX + 1); + + if (this.selectedVideo >= Data.getVideoCount()) { + this.selectedVideo = Data.getVideoCount() -1; + } + var first_item = this.selectedVideo - Display.currentWindow; + + alert("selectPageDown: this.selectedVideo= " + this.selectedVideo + " first_item= " + first_item); + Display.setVideoList(this.selectedVideo, first_item); +}; + +Main.nextVideo = function(no) { + this.selectedVideo = (this.selectedVideo + no) % Data.getVideoCount(); + alert("nextVideo= " + this.selectedVideo); +}; + +Main.previousVideo = function(no) { + + this.selectedVideo = (this.selectedVideo - no); + if (this.selectedVideo < 0) { + this.selectedVideo += Data.getVideoCount(); + } + alert("previousVideo= " + this.selectedVideo); + +}; + +Main.selectNextVideo = function(down) +{ + Player.stopVideo(); + Main.nextVideo(1); + +// this.updateCurrentVideo(down); + Display.setVideoListPosition(this.selectedVideo, down); +}; + +Main.selectPreviousVideo = function(up) +{ + Player.stopVideo(); + Main.previousVideo(1); + +// this.updateCurrentVideo(up); + Display.setVideoListPosition(this.selectedVideo, up); +}; + + + +Main.setMuteMode = function() +{ + if (this.mute != this.YMUTE) + { + var volumeElement = document.getElementById("volumeInfo"); + //Audio.plugin.SetSystemMute(true); + Audio.plugin.SetUserMute(true); + document.getElementById("volumeBar").style.backgroundImage = "url(Images/muteBar.png)"; + document.getElementById("volumeIcon").style.backgroundImage = "url(Images/mute.png)"; + widgetAPI.putInnerHTML(volumeElement, "MUTE"); + this.mute = this.YMUTE; + } +}; + +Main.noMuteMode = function() +{ + if (this.mute != this.NMUTE) + { + Audio.plugin.SetUserMute(false); + document.getElementById("volumeBar").style.backgroundImage = "url(Images/volumeBar.png)"; + document.getElementById("volumeIcon").style.backgroundImage = "url(Images/volume.png)"; + Display.setVolume( Audio.getVolume() ); + this.mute = this.NMUTE; + } +}; + +Main.muteMode = function() +{ + switch (this.mute) + { + case this.NMUTE: + this.setMuteMode(); + break; + + case this.YMUTE: + this.noMuteMode(); + break; + + default: + alert("ERROR: unexpected mode in muteMode"); + break; + } +}; + +// ----------------------------------------------- + +Main.getKeyCode = function(code) { + var res = ""; + switch(code) { + case tvKey.KEY_1: + res = "KEY_1"; + break; + case tvKey.KEY_2: + res = "KEY_2"; + break; + case tvKey.KEY_3: + res = "KEY_3"; + break; + case tvKey.KEY_4: + res = "KEY_4"; + break; + case tvKey.KEY_5: + res = "KEY_5"; + break; + case tvKey.KEY_6: + res = "KEY_6"; + break; + case tvKey.KEY_7: + res = "KEY_7"; + break; + case tvKey.KEY_8: + res = "KEY_8"; + break; + case tvKey.KEY_9: + res = "KEY_9"; + break; + + case tvKey.KEY_TOOLS: + res = "KEY_TOOLS"; + break; + + case tvKey.KEY_TOOLS: + res = "KEY_TOOLS"; + break; + + case tvKey.KEY_TOOLS: + res = "KEY_TOOLS"; + break; + + case tvKey.KEY_UP: + res = "KEY_UP"; + break; + + case tvKey.KEY_DOWN: + res = "KEY_DOWN"; + break; + + case tvKey.KEY_LEFT: + res = "KEY_LEFT"; + break; + + case tvKey.KEY_RIGHT: + res = "KEY_RIGHT"; + break; + + case tvKey.KEY_WHEELDOWN: + res = "KEY_WHEELDOWN"; + break; + + case tvKey.KEY_WHEELUP: + res = "KEY_WHEELUP"; + break; + + case tvKey.KEY_ENTER: + res = "KEY_ENTER"; + break; + + case tvKey.KEY_INFO: + res = "KEY_INFO"; + break; + + case tvKey.KEY_EXIT: + res = "KEY_EXIT"; + break; + + case tvKey.KEY_RETURN: + res = "KEY_RETURN"; + break; + + case tvKey.KEY_RED: + res = "KEY_RED"; + break; + + case tvKey.KEY_GREEN: + res = "KEY_GREEN"; + break; + + case tvKey.KEY_YELLOW: + res = "KEY_YELLOW"; + break; + + case tvKey.KEY_BLUE: + res = "KEY_BLUE"; + break; + + case tvKey.KEY_INFOLINK: + res = "KEY_INFOLINK"; + break; + + case tvKey.KEY_RW: + res = "KEY_RW"; + break; + + case tvKey.KEY_PAUSE: + res = "KEY_PAUSE"; + break; + + case tvKey.KEY_FF: + res = "KEY_FF"; + break; + + case tvKey.KEY_PLAY: + res = "KEY_PLAY"; + break; + + case tvKey.KEY_STOP: + res = "KEY_STOP"; + break; + + case tvKey.KEY_EMPTY: + res = "KEY_EMPTY"; + break; + + case tvKey.KEY_PRECH: + res = "KEY_PRECH"; + break; + + case tvKey.KEY_SOURCE: + res = "KEY_SOURCE"; + break; + + case tvKey.KEY_CHLIST: + res = "KEY_CHLIST"; + break; + + case tvKey.KEY_MENU: + res = "KEY_MENU"; + break; + + case tvKey.KEY_WLINK: + res = "KEY_WLINK"; + break; + + case tvKey.KEY_CC: + res = "KEY_CC"; + break; + + case tvKey.KEY_CONTENT: + res = "KEY_CONTENT"; + break; + + case tvKey.KEY_FAVCH: + res = "KEY_FAVCH"; + break; + + case tvKey.KEY_REC: + res = "KEY_REC"; + break; + + case tvKey.KEY_EMODE: + res = "KEY_EMODE"; + break; + + case tvKey.KEY_DMA: + res = "KEY_DMA"; + break; + + case tvKey.KEY_VOL_UP: + res = "KEY_VOL_UP"; + break; + + case tvKey.KEY_VOL_DOWN: + res = "KEY_VOL_DOWN"; + break; + + case tvKey.KEY_PANEL_CH_UP: + res = "KEY_PANEL_CH_UP"; + break; + + case tvKey.KEY_PANEL_CH_DOWN: + res = "KEY_PANEL_CH_DOWN"; + break; + + case tvKey.KEY_PANEL_VOL_UP: + res = "KEY_PANEL_VOL_UP"; + break; + + case tvKey.KEY_PANEL_VOL_DOWN: + res = "KEY_PANEL_VOL_DOWN"; + break; + + case tvKey.KEY_PANEL_ENTER: + res = "KEY_PANEL_ENTER"; + break; + + case tvKey.KEY_PANEL_RETURN: + res = "KEY_PANEL_RETURN"; + break; + + case tvKey.KEY_PANEL_SOURCE: + res = "KEY_PANEL_SOURCE"; + break; + + case tvKey.KEY_PANEL_MENU: + res = "KEY_PANEL_MENU"; + break; + + case tvKey.KEY_PANEL_POWER: + res = "KEY_PANEL_POWER"; + break; + + + default: + res = "Unknown Key (" + code + ")"; + break; + } + return res; +}; + +//--------------------------------------------------- +// PlayState Key Handler +//--------------------------------------------------- + +function cPlayStateKeyHndl(def_hndl) { + this.defaultKeyHandler = def_hndl; + this.handlerName = "PlayStateKeyHanlder"; + alert(this.handlerName + " created"); + +}; + + +cPlayStateKeyHndl.prototype.handleKeyDown = function () { + var keyCode = event.keyCode; + + if(Player.getState() == Player.STOPPED) { + alert("ERROR: Wrong state - STOPPED"); + return; + } + + alert(this.handlerName+": Key pressed: " + Main.getKeyCode(keyCode)); + + switch(keyCode) + { + case tvKey.KEY_1: + alert("KEY_1 pressed"); + Display.showProgress(); + Player.jumpToVideo(10); + break; + case tvKey.KEY_2: + alert("KEY_2 pressed"); + Display.showProgress(); + Player.jumpToVideo(20); + break; + case tvKey.KEY_3: + alert("KEY_3 pressed"); + Display.showProgress(); + Player.jumpToVideo(30); + break; + case tvKey.KEY_4: + alert("KEY_4 pressed"); + Display.showProgress(); + Player.jumpToVideo(40); + break; + case tvKey.KEY_5: + alert("KEY_5 pressed"); + Display.showProgress(); + Player.jumpToVideo(50); + break; + case tvKey.KEY_6: + alert("KEY_6 pressed"); + Display.showProgress(); + Player.jumpToVideo(60); + break; + case tvKey.KEY_7: + alert("KEY_7 pressed"); + Display.showProgress(); + Player.jumpToVideo(70); + break; + case tvKey.KEY_8: + alert("KEY_8 pressed"); + Display.showProgress(); + Player.jumpToVideo(80); + break; + case tvKey.KEY_9: + alert("KEY_9 pressed"); + Display.showProgress(); + Player.jumpToVideo(90); + break; + + case tvKey.KEY_RIGHT: + case tvKey.KEY_FF: + alert("FF"); + Display.showProgress(); + Player.skipForwardVideo(); + break; + + case tvKey.KEY_LEFT: + case tvKey.KEY_RW: + alert("RW"); + Display.showProgress(); + Player.skipBackwardVideo(); + break; + + case tvKey.KEY_ENTER: + case tvKey.KEY_PLAY: + case tvKey.KEY_PANEL_ENTER: + alert("ENTER"); + if(Player.getState() == Player.PAUSED) { + Player.resumeVideo(); + } + Display.showProgress(); + break; + case tvKey.KEY_RETURN: + case tvKey.KEY_PANEL_RETURN: + case tvKey.KEY_STOP: + alert("STOP"); +// Player.setWindow(); + Player.stopVideo(); + break; + case tvKey.KEY_PAUSE: + alert("PAUSE"); + Player.pauseVideo(); + break; + + case tvKey.KEY_UP: + case tvKey.KEY_PANEL_VOL_UP: + case tvKey.KEY_VOL_UP: + alert("VOL_UP"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(0); + break; + + case tvKey.KEY_DOWN: + case tvKey.KEY_PANEL_VOL_DOWN: + case tvKey.KEY_VOL_DOWN: + alert("VOL_DOWN"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(1); + break; + + default: + alert("Calling Default Key Hanlder"); + this.defaultKeyHandler.handleDefKeyDown(keyCode); + break; + } +}; + + +//--------------------------------------------------- +// Live Play State Key Handler +//--------------------------------------------------- + +function cLivePlayStateKeyHndl(def_hndl) { + this.defaultKeyHandler = def_hndl; + this.handlerName = "LivePlayStateKeyHanlder"; + alert(this.handlerName + " created"); + +}; + + +cLivePlayStateKeyHndl.prototype.handleKeyDown = function () { + var keyCode = event.keyCode; + + if(Player.getState() == Player.STOPPED) { + alert("ERROR: Wrong state - STOPPED"); + return; + } + + alert(this.handlerName+": Key pressed: " + Main.getKeyCode(keyCode)); + + switch(keyCode) { + case tvKey.KEY_1: + case tvKey.KEY_CH_UP: + alert("Prog Up"); + Display.showProgress(); + Player.stopVideo(); + Main.previousVideo(1); + + Main.playItem(); + break; + + case tvKey.KEY_4: + case tvKey.KEY_CH_DOWN: + alert("Prog Down"); + Display.showProgress(); + Player.stopVideo(); + Main.nextVideo(1); + + Main.playItem(); + break; + + case tvKey.KEY_ENTER: + case tvKey.KEY_PLAY: + case tvKey.KEY_PANEL_ENTER: + alert("ENTER"); + Display.hide(); + Display.showProgress(); + break; + case tvKey.KEY_LEFT: + case tvKey.KEY_RETURN: + case tvKey.KEY_PANEL_RETURN: + case tvKey.KEY_STOP: + alert("STOP"); + Player.stopVideo(); + Display.setVideoList(Main.selectedVideo); + Display.show(); + break; + case tvKey.KEY_PAUSE: + alert("PAUSE"); + break; + + case tvKey.KEY_UP: + case tvKey.KEY_PANEL_VOL_UP: + case tvKey.KEY_VOL_UP: + alert("VOL_UP"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(0); + break; + + case tvKey.KEY_DOWN: + case tvKey.KEY_PANEL_VOL_DOWN: + case tvKey.KEY_VOL_DOWN: + alert("VOL_DOWN"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(1); + break; + + default: + this.defaultKeyHandler.handleDefKeyDown(keyCode); + break; + } +}; + +//--------------------------------------------------- +//Menu Key Handler +//--------------------------------------------------- +function cMenuKeyHndl (def_hndl) { + this.defaultKeyHandler = def_hndl; + this.handlerName = "MenuKeyHandler"; + alert(this.handlerName + " created"); + +}; + +cMenuKeyHndl.prototype.handleKeyDown = function () { + var keyCode = event.keyCode; + alert(this.handlerName+": Key pressed: " + Main.getKeyCode(keyCode)); + + switch(keyCode) { + + + case tvKey.KEY_RIGHT: + alert("Right"); + Main.selectPageDown(Main.DOWN); + break; + + case tvKey.KEY_LEFT: + alert("Left"); + Main.selectPageUp(Main.UP); + break; + + case tvKey.KEY_ENTER: + case tvKey.KEY_PLAY: + case tvKey.KEY_PANEL_ENTER: + alert("ENTER"); + + if (Data.getCurrentItem().childs[Main.selectedVideo].isFolder == true) { + alert ("selectFolder= " +Main.selectedVideo); + Data.selectFolder(Main.selectedVideo); + Main.selectedVideo= 0; + Display.setVideoList(Main.selectedVideo); + } + else{ + Display.hide(); + Display.showProgress(); + + Main.playItem(); + } + break; + + case tvKey.KEY_EXIT: + case tvKey.KEY_RETURN: + case tvKey.KEY_PANEL_RETURN: + if (Data.isRootFolder() == true) { + alert ("root reached"); + Main.changeState(0); + } + else { + Main.selectedVideo = Data.folderUp(); + alert("folderUp selectedVideo= " + Main.selectedVideo); + Display.setVideoList(Main.selectedVideo); + } + break; + + + case tvKey.KEY_DOWN: + alert("DOWN"); + Main.selectNextVideo(Main.DOWN); + break; + + case tvKey.KEY_UP: + alert("UP"); + Main.selectPreviousVideo(Main.UP); + break; + + default: + this.defaultKeyHandler.handleDefKeyDown(keyCode); + break; + } +}; + + +//--------------------------------------------------- +// Select Menu Key Handler +//--------------------------------------------------- +function cSelectMenuKeyHndl (def_hndl) { + this.defaultKeyHandler = def_hndl; + this.handlerName = "SelectMenuKeyHandler"; + alert(this.handlerName + " created"); + + this.select = 1; + this.selectMax = 4; // Highest Select Entry +}; + +cSelectMenuKeyHndl.prototype.handleKeyDown = function () { + var keyCode = event.keyCode; + alert(this.handlerName+": Key pressed: " + Main.getKeyCode(keyCode)); + + switch(keyCode) { + + case tvKey.KEY_ENTER: + case tvKey.KEY_PLAY: + case tvKey.KEY_PANEL_ENTER: + alert("ENTER"); + alert ("CurSelect= " + this.select); + + Main.changeState (this.select); + + case tvKey.KEY_DOWN: + Display.unselectItem(document.getElementById("selectItem"+this.select)); + if (++this.select > this.selectMax) + this.select = 1; + Display.selectItem(document.getElementById("selectItem"+this.select)); + alert("DOWN " +this.select); + break; + + case tvKey.KEY_UP: + Display.unselectItem(document.getElementById("selectItem"+this.select)); + + if (--this.select < 1) + this.select = this.selectMax; + Display.selectItem(document.getElementById("selectItem"+this.select)); + + alert("UP "+ this.select); + break; + default: + this.defaultKeyHandler.handleDefKeyDown(keyCode); + break; + } +}; + + +//--------------------------------------------------- +// Default Key Handler +//--------------------------------------------------- + +function cDefaulKeyHndl() { + this.handlerName = "DefaultKeyHanlder"; + alert(this.handlerName + " created"); +}; + +cDefaulKeyHndl.prototype.handleDefKeyDown = function (keyCode) { + alert("cDefaulKeyHndl::handleKeyDown: " + Main.getKeyCode(keyCode)); + + switch(keyCode) { + case tvKey.KEY_EXIT: + alert(this.handlerName +"Exit"); + Player.stopVideo(); + widgetAPI.sendReturnEvent(); + break; + + case tvKey.KEY_VOL_UP: + alert(this.handlerName + "VOL_UP"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(0); + break; + + case tvKey.KEY_VOL_DOWN: + alert(this.handlerName + "VOL_DOWN"); + Display.showVolume(); + if(Main.mute == 0) + Audio.setRelativeVolume(1); + break; + case tvKey.KEY_MUTE: + alert(this.handlerName + "MUTE"); + Main.muteMode(); + break; + default: + alert(this.handlerName + "Unhandled key"); + break; + } +}; + + +// --------------------------------------------- diff --git a/smarttv-client/Javascript/Network.js b/smarttv-client/Javascript/Network.js new file mode 100755 index 0000000..1dfcafc --- /dev/null +++ b/smarttv-client/Javascript/Network.js @@ -0,0 +1,25 @@ +var Network = { + plugin : null, + ownMac : "", + ownGw : "" +}; + +Network.init = function () { + this.plugin = document.getElementById("pluginNetwork"); + var nw_type = this.plugin.GetActiveType(); + if ((nw_type == 0) || (nw_type == 1)) { + this.ownMac = this.plugin.GetMAC(nw_type); + this.ownGw = this.plugin.GetGateway(nw_type); + } + alert( "ownMac= " + this.ownMac); + alert ("ownGw= " + this.ownGw); +} ; + + +Network.getMac = function () { + return this.ownMac; +}; + +Network.getGateway = function () { + return this.ownGw; +}; \ No newline at end of file diff --git a/smarttv-client/Javascript/Options.js b/smarttv-client/Javascript/Options.js new file mode 100755 index 0000000..d60a9ff --- /dev/null +++ b/smarttv-client/Javascript/Options.js @@ -0,0 +1,66 @@ +var Options = { + imeBox : null +}; + +Options.init = function() { + _g_ime.Recog_use_YN = false; + _g_ime.keySet = '12key'; + + this.imeBox = new IMEShell("widgetServerAddr", Options.onImeCreated, 'de'); + alert ("Options Initiated"); +}; + +Options.onComplete = function () { + alert("Colpleted"); +}; + +Options.onEnter = function () { + alert("Enter: " + document.getElementById("widgetServerAddr").value ); + Config.updateContext(document.getElementById("widgetServerAddr").value); + + document.getElementById('widgetServerAddr').blur(); + + document.getElementById("optionsScreen").style.display="none"; + + if (Config.firstLaunch == true) + Main.state = 1; + Main.changeState(0); + + Config.fetchConfig(); +// Main.enableKeys(); +}; + +Options.onBlue = function () { + var val = document.getElementById("widgetServerAddr").value + "."; + Options.imeBox.setString(val); +}; + +Options.onImeCreated = function(obj) { +// _g_ime.keySet ("12key"); +// obj.setKeySetFunc('12key'); + + obj.setKeyFunc(tvKey.KEY_RETURN, function(keyCode) { widgetAPI.sendReturnEvent(); return false; } ); + obj.setKeyFunc(tvKey.KEY_EXIT, function(keyCode) { widgetAPI.sendExitEvent(); return false; } ); + + obj.setKeypadPos(650, 135); + obj.setWordBoxPos(18, 6); + obj.setKeyFunc(tvKey.KEY_BLUE, Options.onBlue); + + obj.setString(Config.serverAddr); + obj.setEnterFunc(Options.onEnter); + + if (obj.setMode("_num") == false) { + Main.log("obj.setMode(\"_num\") returns false"); + } + + Options.imeBox.setOnCompleteFunc(Options.onComplete); + + Options.onReady (); +}; + +Options.onReady = function () { + document.getElementById('widgetServerAddr').focus(); + alert ("KeySet= " + this.imeBox.getKeySet()); +}; + + diff --git a/smarttv-client/Javascript/Player.js b/smarttv-client/Javascript/Player.js new file mode 100755 index 0000000..a04c26f --- /dev/null +++ b/smarttv-client/Javascript/Player.js @@ -0,0 +1,350 @@ +var Player = +{ + plugin : null, + isLive : false, + isRecording : false, + + startTime : 0, + duration : 0, + + state : 0, + cptOffset : 0, // millis + curPlayTime : 0, // millis + totalTime : -1, // millis + + curPlayTimeStr : "00:00:00", // millis + totalTimeStr : "", + stopCallback : null, /* Callback function to be set by client */ + errorCallback : null, + originalSource : null, + + bufferState : 0, // buffer state in % + + STOPPED : 0, + PLAYING : 1, + PAUSED : 2, + FORWARD : 3, + REWIND : 4 +}; + +Player.init = function() { + var success = true; + alert("success vale : " + success); + this.state = this.STOPPED; + + this.plugin = document.getElementById("pluginPlayer"); + + if (!this.plugin) + { + alert("success vale this.plugin : " + success); + success = false; + } + + var vermsg = this.plugin.GetPlayerVersion(); + alert ("player plugin version: " +vermsg); + + this.plugin.OnCurrentPlayTime = 'Player.OnCurrentPlayTime'; + this.plugin.OnStreamInfoReady = 'Player.OnStreamInfoReady'; + this.plugin.OnBufferingStart = 'Player.onBufferingStart'; + this.plugin.OnBufferingProgress = 'Player.onBufferingProgress'; + this.plugin.OnBufferingComplete = 'Player.onBufferingComplete'; + this.plugin.OnConnectionFailed = 'Player.OnConnectionFailed'; // fails to connect to the streaming server + this.plugin.OnStreamNotFound = 'Player.OnStreamNotFound'; // 404 file not found + this.plugin.OnNetworkDisconnected = 'Player.OnNetworkDisconnected'; // when the ethernet is disconnected or the streaming server stops supporting the content in the middle of streaming. + this.plugin.OnRenderingComplete = 'Player.OnRenderingComplete'; + + alert("success= " + success); + return success; +}; + +Player.deinit = function() +{ + alert("Player deinit !!! " ); + + if (this.plugin) + { + this.plugin.Stop(); + } +}; + +Player.setWindow = function() { +// this.plugin.SetDisplayArea(458, 58, 472, 270); +}; + +Player.setFullscreen = function() { + this.plugin.SetDisplayArea(0, 0, 960, 540); +}; + +Player.setBuffer = function (btr){ + var res = true; +// var m_bitrate = Config.tgtBufferBitrate; +// var buffer_sec = Config.totalBufferDuration; +// var init_buffer_perc = Config.initialBuffer; +// var pend_buffer_perc = Config.pendingBuffer; + + var buffer_byte = (Config.totalBufferDuration * Config.tgtBufferBitrate) / 8.0; + + Main.log("Seting TotalBufferSize to " + Math.round(buffer_byte) +"Byte dur= " +Config.totalBufferDuration + "sec init_buffer_perc= " +Config.initialBuffer +"% pend_buffer_perc= " +Config.pendingBuffer + "% initialTimeOut= " +Config.initialTimeOut + "sec"); + + //The SetTotalBufferSize function sets the streaming buffer size of media player. + res = this.plugin.SetTotalBufferSize(Math.round(buffer_byte)); + if (res == false) { + Display.showPopup("SetTotalBufferSize(" + Math.round(buffer_byte) +") returns error"); + Main.log("SetTotalBufferSize(" + Math.round(buffer_byte) +") returns error"); + } + + // The SetInitialBuffer function sets the first buffering size as percentage of buffer size before starting playback. + res = this.plugin.SetInitialBuffer(Math.round( buffer_byte * Config.initialBuffer/ 100.0)); + if (res == false) { + Display.showPopup("SetInitialBuffer(" + Math.round(buffer_byte * Config.initialBuffer/ 100.0) +") returns error"); + Main.log("SetInitialBuffer(" + Math.round(buffer_byte * Config.initialBuffer/ 100.0) +") returns error"); + } + //he SetInitialTimeOut function sets the maximum time out value for initial buffering before starting playback. + res = this.plugin.SetInitialTimeOut(Config.initialTimeOut); + if (res == false) { + Display.showPopup("SetInitialTimeOut(" + 2 +") returns error"); + Main.log("SetInitialTimeOut(" + 2 +") returns error"); + } + + // The SetPendingBuffer function sets the size of a buffer as percentage of total buffer size that media player goes out from buffering status. + res = this.plugin.SetPendingBuffer(Math.round(buffer_byte * Config.pendingBuffer /100.0)); + if (res == false) { + Display.showPopup("SetPendingBuffer(" + Math.round(buffer_byte * Config.pendingBuffer /100.0) +") returns error"); + Main.log("SetPendingBuffer(" + Math.round(buffer_byte * Config.pendingBuffer /100.0) +") returns error"); + } + +}; + +Player.setVideoURL = function(url) { + this.url = url; + alert("URL = " + this.url); +}; + +Player.setCurrentPlayTimeOffset = function(val) { + // val in milli sec + this.cptOffset = val; +// Display.showPopup("CurrentPlayTimeOffset= " + this.cptOffset); +}; + +Player.playVideo = function() { + if (this.url == null) { + alert("No videos to play"); + } + else + { + +// Player.curPlayTime = 0; + Display.updatePlayTime(); + + Display.status("Play"); + Display.showStatus(); + Display.showProgress(); + this.state = this.PLAYING; + +// if (this.plugin.InitPlayer(this.url) == false) +// Display.showPopup("InitPlayer returns false"); + + Player.setBuffer(15000000.0); + + alert ("StartPlayback for " + this.url); +// if (this.plugin.StartPlayback() == false) +// Display.showPopup("StartPlayback returns false"); + + this.plugin.Play( this.url ); + Audio.plugin.SetSystemMute(false); + } +}; + +Player.pauseVideo = function() { + Display.showProgress(); + Main.log("pauseVideo"); + + this.state = this.PAUSED; + Display.status("Pause"); + var res = this.plugin.Pause(); + if (res == false) + Display.showPopup("pause ret= " + ((res == true) ? "True" : "False")); +}; + +Player.stopVideo = function() { + if (this.state != this.STOPPED) { + this.state = this.STOPPED; + Display.status("Stop"); + this.plugin.Stop(); + Player.bufferState = 0; +// Display.setTime(0); + + if (this.stopCallback) { + this.stopCallback(); + } + } + else { + alert("Ignoring stop request, not in correct state"); + } +}; + +Player.resumeVideo = function() { + Main.log("resumeVideo"); + Display.showProgress(); + this.state = this.PLAYING; + Display.status("Play"); + var res = this.plugin.Resume(); + if (res == false) + Display.showPopup("resume ret= " + ((res == true) ? "True" : "False")); + +}; + +Player.jumpToVideo = function(percent) { + if (this.isLive == true) { + return; + } + Player.bufferState = 0; + Display.showProgress(); + if (this.state != this.PLAYING) { + alert ("Player not Playing"); + return; + } + if (this.totalTime == -1 && this.isLive == false) + this.totalTime = this.plugin.GetDuration(); + var tgt = Math.round(((percent-2)/100.0) * this.totalTime/ 1000.0); + + alert("jumpToVideo= " + percent + "% of " + (this.totalTime/1000) + "sec tgt = " + tgt + "sec curPTime= " + (this.curPlayTime/1000) +"sec"); +// Display.showPopup("jumpToVideo= " + percent + "% of " + (this.totalTime/1000) + "sec
--> tgt = " + tgt + "sec curPTime= " + (this.curPlayTime/1000)+"sec"); + this.plugin.Stop(); + + Display.showStatus(); + + var res = this.plugin.ResumePlay(this.url, tgt ); + if (res == false) + Display.showPopup("ResumePlay ret= " + ((res == true) ? "True" : "False")); +}; + +Player.skipForwardVideo = function() { + var res = this.plugin.JumpForward(Config.skipDuration); + if (res == false) + Display.showPopup("Jump Forward ret= " + ((res == true) ? "True" : "False")); +}; + +Player.skipBackwardVideo = function() { + var res = this.plugin.JumpBackward(Config.skipDuration); + if (res == false) + Display.showPopup("Jump Backward ret= " + ((res == true) ? "True" : "False")); +}; + +Player.getState = function() { + return this.state; +}; + +// ------------------------------------------------ +// Global functions called directly by the player +//------------------------------------------------ + +Player.onBufferingStart = function() { + Main.log("Buffer Start: " + Player.curPlayTime); + Player.bufferStartTime = new Date().getTime(); + + Player.bufferState = 0; + Display.bufferUpdate(); + // should trigger from here the overlay + Display.showProgress(); + Display.status("Buffering..."); + Display.showStatus(); +}; + +Player.onBufferingProgress = function(percent) +{ + // should trigger from here the overlay + Display.status("Buffering:" + percent + "%"); + + Player.bufferState = percent; + Display.bufferUpdate(); + Display.showProgress(); +}; + +Player.onBufferingComplete = function() { + Display.status("Play"); + Display.hideStatus(); + + Main.log("Buffer Completed - Buffering Duration= " + (new Date().getTime() - Player.bufferStartTime) + " ms"); + + Player.bufferState = 100; + Display.bufferUpdate(); + Display.showProgress(); + + Player.setFullscreen(); + Display.hide(); + + Main.log("onBufferingComplete "); +/* Player.pauseVideo(); + window.setTimeout(Player.resumeVideo, 1000); */ +}; + + +Player.OnCurrentPlayTime = function(time) { + Player.curPlayTime = parseInt(time) + parseInt(Player.cptOffset); + +// alert ("OnCurrentPlayTime time= " + time + " this.curPlayTime= " +this.curPlayTime ); +// Display.setTime(Player.curPlayTime); + + // Update the Current Play Progress Bar + Display.updateProgressBar(); + + if (Player.isRecording == true) { + Display.updateRecBar(Player.startTime, Player.duration); + } + Player.curPlayTimeStr = Display.getHumanTimeRepresentation(Player.curPlayTime); + Display.updatePlayTime(); +}; + + +Player.OnStreamInfoReady = function() { + alert("*** OnStreamInfoReady ***"); +// Display.showPopup("*** OnStreamInfoReady *** "); +// Display.showPopup("GetCurrentBitrates= " + Player.plugin.GetCurrentBitrates()); + Main.log("GetCurrentBitrates= " + Player.plugin.GetCurrentBitrates()); + if ((Player.isLive == false) && (Player.isRecording == false)) { + Player.totalTime = Player.plugin.GetDuration(); + } +// Display.updateTotalTime (Player.totalTime); + Player.totalTimeStr = Display.getHumanTimeRepresentation(Player.totalTime); + + +// alert("totalTime= " + Player.totalTime + " totalTimeStr= " +Player.totalTimeStr); +// Display.setTotalTime(totalTime); + + +/* var height = Player.plugin.GetVideoHeight(); + var width = Player.GetVideoWidth(); + Display.showPopup("Resolution= " + height + " x " +width); + alert("Resolution= " + height + " x " +width); +*/ +}; + +Player.OnRenderingComplete = function() { + // Do Something + Player.stopVideo(); +}; + +Player.OnConnectionFailed = function() { + // fails to connect to the streaming server + alert ("ERROR: Failed to connect to the streaming server"); +// widgetAPI.putInnerHTML(document.getElementById("popup"), "Failed to connect to the streaming server"); + Display.showPopup("Failed to connect to the streaming server"); +}; + +Player.OnStreamNotFound = function() { +// 404 file not found + alert ("ERROR: Stream Not Found"); +// widgetAPI.putInnerHTML(document.getElementById("popup"), "Stream Not Found"); + Display.showPopup("Stream Not Found"); + +}; + +Player.OnNetworkDisconnected = function() { +// when the ethernet is disconnected or the streaming server stops supporting the content in the middle of streaming. + alert ("ERROR: Lost Stream (Unavailable?)"); + +// widgetAPI.putInnerHTML(document.getElementById("popup"), "Lost Stream (Unavailable?)"); + Display.showPopup("Lost Stream (Unavailable?)"); +}; + diff --git a/smarttv-client/Javascript/Server.js b/smarttv-client/Javascript/Server.js new file mode 100755 index 0000000..588906b --- /dev/null +++ b/smarttv-client/Javascript/Server.js @@ -0,0 +1,141 @@ +var Server = +{ + dataReceivedCallback : null, + errorCallback : null, + doSort : false, + retries : 0, + + XHRObj : null +}; + +Server.init = function() +{ + var success = true; + + var splashElement = document.getElementById("splashStatus"); + widgetAPI.putInnerHTML(splashElement, "Starting Up"); + + if (this.XHRObj) { + this.XHRObj.destroy(); + this.XHRObj = null; + } + + return success; +}; + +Server.setSort = function (val) { + this.doSort = val; +}; + +Server.fetchVideoList = function(url) { + alert("fetching Videos url= " + url); + if (this.XHRObj == null) { + this.XHRObj = new XMLHttpRequest(); + } + + if (this.XHRObj) { + this.XHRObj.onreadystatechange = function() + { + var splashElement = document.getElementById("splashStatus"); + widgetAPI.putInnerHTML(splashElement, "State" + Server.XHRObj.readyState); + + if (Server.XHRObj.readyState == 4) { + Server.createVideoList(); + } + }; + + this.XHRObj.open("GET", url, true); + this.XHRObj.send(null); + } + else { + var splashElement = document.getElementById("splashStatus"); + widgetAPI.putInnerHTML(splashElement, "Failed !!!" ); + Display.showPopup("Failed to create XHR"); + + if (this.errorCallback != null) { + this.errorCallback("ServerError"); + } + } +}; + +Server.createVideoList = function() { + alert ("creating Video list now"); + var splashElement = document.getElementById("splashStatus"); + widgetAPI.putInnerHTML(splashElement, "Creating Video list now" ); + + if (this.XHRObj.status != 200) { + widgetAPI.putInnerHTML(splashElement, "XML Server Error " + this.XHRObj.status); + Display.status("XML Server Error " + this.XHRObj.status); + Display.showPopup("XML Server Error " + this.XHRObj.status); + if (this.errorCallback != null) { + this.errorCallback("ServerError"); + } + } + else + { + var xmlResponse = this.XHRObj.responseXML; + if (xmlResponse == null) { + Display.status("xmlResponse == null" ); + widgetAPI.putInnerHTML(splashElement, "Error in XML File "); + Display.showPopup("Error in XML File"); + if (this.errorCallback != null) { + this.errorCallback("XmlError"); + } + return; + } + var xmlElement = xmlResponse.documentElement; +// var xmlElement = this.XHRObj.responseXML.documentElement; + + if (!xmlElement) { + widgetAPI.putInnerHTML(splashElement, "Failed to get valid XML!!!"); + Display.status("Failed to get valid XML"); + Display.showPopup("Failed to get valid XML"); + return; + } + else + { + widgetAPI.putInnerHTML(splashElement, "Parsing ..."); + var items = xmlElement.getElementsByTagName("item"); + + for (var index = 0; index < items.length; index++) { + + var titleElement = items[index].getElementsByTagName("title")[0]; + var progElement = items[index].getElementsByTagName("programme")[0]; + var descriptionElement = items[index].getElementsByTagName("description")[0]; + var linkElement = items[index].getElementsByTagName("link")[0]; +// var startstrVal = ""; + var startVal =0; + var durVal =0; + try { +// startstrVal = items[index].getElementsByTagName("startstr")[0].firstChild.data; + startVal = parseInt(items[index].getElementsByTagName("start")[0].firstChild.data); + durVal = parseInt(items[index].getElementsByTagName("duration")[0].firstChild.data); + } + catch (e) { + + alert("ERROR: "+e); + } + + var desc = descriptionElement.firstChild.data; + + if (titleElement && linkElement) { + var title_list = titleElement.firstChild.data.split("~"); + Data.addItem( title_list, {link : linkElement.firstChild.data, + prog: progElement.firstChild.data, + desc: desc, +// startstr: startstrVal, + start: startVal, + dur: durVal}); + } + + } + Data.completed(this.doSort); + widgetAPI.putInnerHTML(splashElement, "Done..."); + + if (this.dataReceivedCallback) + { + this.dataReceivedCallback(); /* Notify all data is received and stored */ + } + } + } +}; -- cgit v1.2.3