28.02.2017, 09:21
(This post was last modified: 28.02.2017, 09:27 by Erwin van der Zwart.)
Hi Josep,
Here is the full (renewed) sample:
BR,
Erwin
Here is the full (renewed) sample:
Code:
$(function(){
setInterval(function(){
// Only poll if current page = 1
//console.log(currentPlanId)
var sonosip = "127.0.0.1"
if (currentPlanId == 1 || currentPlanId == 2 || currentPlanId == 3 ){
if (currentPlanId == 1 ) {
sonosip = "192.168.10.26"
}
if (currentPlanId == 2 ) {
sonosip = "192.168.10.27"
}
if (currentPlanId == 3 ) {
sonosip = "192.168.10.28"
}
// Request data from sonos API
$.post("/apps/data/sonos/sonos.lp",
{ action: "getextendedstate", ip: sonosip },
function(data) {
var res_parsed = JSON.parse(data);
if (typeof data !== 'undefined'){
//console.log(res_parsed)
var protocolinfo = res_parsed[5].trackuri.match("x(.*)://");
//console.log(protocolinfo[0])
// Update text label with additional class 'volume'
$("#plan-" + currentPlanId).find(".volume").html(res_parsed[0].volume + ' %');
// Update text label with additional class 'mute'
$("#plan-" + currentPlanId).find(".mute").html(res_parsed[1].mute);
// Update text label with additional class 'crossfade'
$("#plan-" + currentPlanId).find(".crossfade").html(res_parsed[2].crossfade);
// Update text label with additional class 'playmode'
$("#plan-" + currentPlanId).find(".playmode").html(res_parsed[3].playmode);
// Update text label with additional class 'transport'
$("#plan-" + currentPlanId).find(".transport").html(res_parsed[4].transport);
// Update text label with additional class 'trackuri'
$("#plan-" + currentPlanId).find(".trackuri").html(res_parsed[5].trackuri);
// Update text label with additional class 'duration'
$("#plan-" + currentPlanId).find(".duration").html(res_parsed[6].duration);
// Update text label with additional class 'playingtime'
$("#plan-" + currentPlanId).find(".playingtime").html(res_parsed[7].playingtime);
// Update text label with additional class 'tracktitle'
$("#plan-" + currentPlanId).find(".tracktitle").html(res_parsed[8].tracktitle);
// Update text label with additional class 'creator'
$("#plan-" + currentPlanId).find(".creator").html(res_parsed[9].creator);
// Hide Album when mediatype = radio
if (res_parsed[12].mediatype == 'radio'){
$("#plan-" + currentPlanId).find(".album").css( "display", "none" );
} else {
$("#plan-" + currentPlanId).find(".album").css( "display", "block" );
// Update text label with additional class 'album'
$("#plan-" + currentPlanId).find(".album").html(res_parsed[10].album);
}
// Update image container with additional class 'albumart'
$("#plan-" + currentPlanId).find(".albumart").find("img").attr('src', res_parsed[11].albumart);
// Update text label with additional class 'mediatype'
$("#plan-" + currentPlanId).find(".mediatype").html(res_parsed[12].mediatype);
//$("#plan-" + currentPlanId).find(".trackuri").html(res_parsed[13].trackuri);
//$("#plan-" + currentPlanId).find(".trackurimetadata").html(res_parsed[14].trackurimetadata);
//$("#plan-" + currentPlanId).find(".albumartbase64").html(res_parsed[15].albumartbase64);
//$("#plan-" + currentPlanId).find(".sonosplayerip").html(res_parsed[16].sonosplayerip);
function FormattedTimeToSeconds(formattedtime) {
var a = formattedtime.split(':'); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
return seconds;
}
var passed = 0;
var durationseconds = FormattedTimeToSeconds(res_parsed[6].duration);
var playingtimeseconds = FormattedTimeToSeconds(res_parsed[7].playingtime)
if (durationseconds > playingtimeseconds){
passed = durationseconds - (durationseconds - playingtimeseconds);
passed = Math.floor(((passed / durationseconds) * 100) * 4); // set to * x for each 100px
} else {
passed = 0;
}
$("#plan-" + currentPlanId).find(".playprogress").css("min-width", "0px", 'important');
$("#plan-" + currentPlanId).find(".playprogress").css("height", "15px", 'important');
$("#plan-" + currentPlanId).find(".playprogress").css("border-radius", "0px", 'important');
$("#plan-" + currentPlanId).find(".playprogress").css("max-width", passed + "px", 'important');
$("#plan-" + currentPlanId).find(".playprogress").css("width", passed + "px");
}
}
); }; }, 1000);
});
BR,
Erwin