27.02.2017, 16:52
(This post was last modified: 27.02.2017, 17:37 by Erwin van der Zwart.)
Hi Josep,
Yes almost anything is possible, you just have to know how to do it (;
This one is quite tricky as the duration and playing time are strings like 0:00:00 from sonos so you have to split them, multiply them and calculate the percentage between start and end and the current position.
With this 0-100% (var passed) you can scale a element to your bar.
Here is the code i used in the app:
BR,
Erwin
Yes almost anything is possible, you just have to know how to do it (;
This one is quite tricky as the duration and playing time are strings like 0:00:00 from sonos so you have to split them, multiply them and calculate the percentage between start and end and the current position.
With this 0-100% (var passed) you can scale a element to your bar.
Here is the code i used in the app:
Code:
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(duration);
var playingtimeseconds = FormattedTimeToSeconds(playingtime)
if (durationseconds > playingtimeseconds){
passed = durationseconds - (durationseconds - playingtimeseconds);
passed = Math.floor(((passed / durationseconds) * 100) * 1); // set to * x for each 100px
} else {
passed = 0;
}
BR,
Erwin