Posts

Post not yet marked as solved
0 Replies
120 Views
I have a simple TVML app that displays shop-floor status data, the JS hits a webservice every 60 seconds and pulls an updated TVML string and loads it to the DOM. It works great for about 4 hours then crashes due to a memory leak caused by XMLHttpRequest not being deposed of properly. I've tried various ways to release the object, but nothing seems to have any affect. Any suggestions? Apple TV device log error is: 90 seconds cpu time over 90 seconds (100% cpu average), exceeding limit of 50% cpu over 180 seconds App.onLaunch = function (options) { var ip = options.IP; var refreshRate = options.REFRESH_RATE; //reload js every 15 minutes setTimeout(function () { App.reload() }, 900000); //refresh at passed in interval setInterval(function () { getTemplate(ip) }, refreshRate); loadingMessage(ip); getTemplate(ip); } function pushDoc(doc) { if (doc != null) { navigationDocument.clear(); navigationDocument.pushDocument(doc); } } function getTemplate(ip) { try { var url = "http://GetTemplate?ip=" + ip; var request = new XMLHttpRequest(); request.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { pushDoc(request.responseXML); delete request; request = null; } }; request.responseType = "document"; request.open("GET", url); request.send(); } catch (err) { errorMessage(ip, "getTemplate()", err.message) } } function loadingMessage(ip) { var loadingString = "<?xml version='1.0' encoding='UTF-8' ?>"; loadingString += "<document>"; loadingString += "<alertTemplate>"; loadingString += "<title>IP: " + ip + " - " + now() + "</title>"; loadingString += "<description>Loading...</description>"; loadingString += "</alertTemplate>"; loadingString += "</document>"; var loading = new DOMParser(); var doc = loading.parseFromString(loadingString, "application/xml"); pushDoc(doc); } function errorMessage(ip, func, err) { var errorString = "<?xml version='1.0' encoding='UTF-8' ?>"; errorString += "<document>"; errorString += "<alertTemplate>"; errorString += "<title>IP: " + ip + " - " + now() + "</title>"; errorString += "<description>" + func + " failed! Error is: " + err + "</description>"; errorString += "</alertTemplate>"; errorString += "</document>"; var error = new DOMParser(); var doc = error.parseFromString(errorString, "application/xml"); pushDoc(doc); } function now() { var currentdate = new Date(); var datetime = ((currentdate.getMonth() + 1) < 10 ? '0' : '') + (currentdate.getMonth() + 1) + "/" + (currentdate.getDate() < 10 ? '0' : '') + currentdate.getDate() + "/" + currentdate.getFullYear() + " @ " + (currentdate.getHours() < 10 ? '0' : '') + currentdate.getHours() + ":" + (currentdate.getMinutes() < 10 ? '0' : '') + currentdate.getMinutes() + ":" + (currentdate.getSeconds() < 10 ? '0' : '') + currentdate.getSeconds(); return datetime; }
Posted
by Hbbob.
Last updated
.
Post not yet marked as solved
0 Replies
356 Views
I'm new to tvML, so chances are I'm missing something easy... The script runs fine no errors, video plays, mediaItemWillChange event never fires to play the video again. Any suggestions would be greatly appreciated. App.onLaunch = function (options) { var video = new MediaItem('video', 'https://localhost/file_example_MP4_1920_18MG.mp4'); var player = new Player(); var playlist = new Playlist(); player.playlist = playlist; player.playlist.push(video); var parser = new DOMParser(); var alertString = '<?xml version="1.0" encoding="UTF-8" ?>' + '<document>' + '<alertTemplate>' + '</alertTemplate>' + '</document>'; var alertDoc = parser.parseFromString(alertString, "application/xml"); player.interactiveOverlayDocument = alertDoc; player.interactiveOverlayDismissable = false; player.addEventListener("mediaItemWillChange", function (e) { player.playlist.push(video); }); player.play(); }
Posted
by Hbbob.
Last updated
.