[SOLVED] Chromecast Duration and Player

Hi Folks

  • the duration for the chromecast is in sec.

How Can i display in my sitemap like : 02:10/62.00 ?
2:10 on a total duration of 62 minutes

  • is it possible to move forward 30 sec ?

Thanks!

I don’t use this binding so I can’t answer most of your questions. But for the the duration question, create a JavaScript transform to calculate and convert the minutes to the form you want. For example, the following JS tranform will convert a number of minutes to days,hours,minutes format.

(function(i) {
    if(isNaN(i)) return "NAN";
    var mins = i%60
    var totalhours = Math.floor(i/60)
    var hours = totalhours%24
    var days = Math.floor(totalhours/24)
    var pad = "00";
    return days+":"+(pad+hours).slice(-pad.length)+":"+(pad+mins).slice(-pad.length)+":00";
})(input)
1 Like

Thanks a lot

i have added your function under the transform folder

i have tried to update my item definition

Number duration_CastSalon "T [JS(getMinutes.js):%]" { channel="chromecast:chromecast:CastSalon:duration"}

i am getting this error

2019-06-19 23:59:52.845 [WARN ] [rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1387.6244897959184' on item 'duration_CastSalon' with pattern 'JS(getMinutes.js):%': Cannot format state '1387.6244897959184' to format '%'

you forgot an “s”.

So if I’m right is this converting from seconds right (i = seconds)?

This would be great, now I’m having rules for this, never thought of doing with a js transform…
If not, can you help me create one which converts from seconds? Most of the bindings returns currentTime/Duration in seconds…

No, this one is converting from minutes. I use this transform and just pad the string with “:00” for the seconds. My DIY devices report in seconds and convert the seconds to days:hours:mins:secs on the microcontroller so I don’t have a transform for those.

To handle seconds you would just need to calculate the seconds at the top using the same pattern.

(function(i) {
    if(isNaN(i)) return "NAN";
    var secs = i%60;
    var totalmins = Math.floor(i/60);
    var mins = totalmins%60;
    var totalhours = Math.floor(totalmins/60);
    var hours = totalhours%24;
    var days = Math.floor(totalhours/24);
    return days+":"+(pad+hours).slice(-pad.length)+":"+(pad+mins).slice(-pad.length)+":"+(pad+secs).slice(-pad.length);
})(input)

I just typed in the above, I can’t guarantee it works as typed. I also noticed that my original didn’t have all the semicolons.

Thanks again and again @rlkoshak

5 minutes to save the transform function

and just add this to the item definition

Number currentTime_CastParents "Current Time [JS(getMinutes.js):%s]" { channel="chromecast:chromecast:CastParents:currentTime"}

Brilliant solution because so simple !

But unfortunately, the calculation is inaccurate please, have a look between the source youtube and openhab

This works for me well, fixed the intial js script:

(function(i) {
    if(isNaN(i)) return "NAN";
    var secs = Math.floor(i % 60)
    var mins = Math.floor(i / 60)
    var hours = 0
    if(mins > 60) {
        hours = Math.floor(mins / 60)
        mins = Math.floor(mins % 60)
    }
    var pad = "00";
    return (pad+hours).slice(-pad.length)+":"+(pad+mins).slice(-pad.length)+":"+(pad+secs).slice(-pad.length);
})(input)

This only calculates until hours not days (I don’t think you have a show or anything running for more than a day…)

However little off: Do you use 2.4 stable OH? Do you have a stop channel in one of your Chromecast things?

2 Likes