02.10.2017, 19:59
(This post was last modified: 02.10.2017, 20:34 by Erwin van der Zwart.)
Hi Marc,
No, i just tested it and the command is still available, but i noticed they have changed the structure of the response, that's why you got errors:
Here is the script changed to current response:
BR,
Erwin
No, i just tested it and the command is still available, but i noticed they have changed the structure of the response, that's why you got errors:
Here is the script changed to current response:
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.TrackUri.match("x(.*)://");
//console.log(protocolinfo[0])
// Update text label with additional class 'volume'
$("#plan-" + currentPlanId).find(".volume").html(res_parsed.Volume + ' %');
// Update text label with additional class 'mute'
$("#plan-" + currentPlanId).find(".mute").html(res_parsed.Mute);
// Update text label with additional class 'crossfade'
$("#plan-" + currentPlanId).find(".crossfade").html(res_parsed.Crossfade);
// Update text label with additional class 'playmode'
$("#plan-" + currentPlanId).find(".playmode").html(res_parsed.Playmode);
// Update text label with additional class 'transport'
$("#plan-" + currentPlanId).find(".transport").html(res_parsed.TransportState);
// Update text label with additional class 'trackuri'
$("#plan-" + currentPlanId).find(".trackuri").html(res_parsed.TrackUri);
// Update text label with additional class 'duration'
$("#plan-" + currentPlanId).find(".duration").html(res_parsed.TrackDuration);
// Update text label with additional class 'playingtime'
$("#plan-" + currentPlanId).find(".playingtime").html(res_parsed.Playingtime);
// Update text label with additional class 'tracktitle'
$("#plan-" + currentPlanId).find(".tracktitle").html(res_parsed.TrackTitle);
// Update text label with additional class 'creator'
$("#plan-" + currentPlanId).find(".creator").html(res_parsed.Creator);
// Hide Album when mediatype = radio
if (res_parsed.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.Album);
}
// Update image container with additional class 'albumart'
$("#plan-" + currentPlanId).find(".albumart").find("img").attr('src', res_parsed.AlbumArt);
// Update text label with additional class 'mediatype'
$("#plan-" + currentPlanId).find(".mediatype").html(res_parsed.MediaType);
//$("#plan-" + currentPlanId).find(".trackuri").html(res_parsed.TrackUri);
//$("#plan-" + currentPlanId).find(".trackurimetadata").html(res_parsed.TrackMetadata);
//$("#plan-" + currentPlanId).find(".sonosplayerip").html(res_parsed.ip);
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.TrackDuration);
var playingtimeseconds = FormattedTimeToSeconds(res_parsed.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