Show the time correctly

Guys, I know that for the vast majority it’s very easy but I’m getting beaten and I’m not getting it.

I got a very useful formula right here on the Forum that allows me to show the audio time in progress.

The formula is as follows:

"Audio Monitoring: " + “\n” + "Total Time: " + IF(FLOOR(outputs[“Get audio playback info”].playback.duration/ 60)<10 ,“0”+ FLOOR(outputs[“Get audio playback info”].playback.duration/ 60),FLOOR(outputs[“Get audio playback info”].playback.duration/ 60) )+ “:” + LEFT_PAD(STRING(FLOOR(outputs[“Get audio playback info”].playback.duration % 60)), 2, “0”)+ " - Current Time: " + IF(FLOOR(outputs[“Get audio playback info”].playback.currentTime/ 60)<10 ,“0”+ FLOOR(outputs[“Get audio playback info”].playback.currentTime/ 60),FLOOR(outputs[“Get audio playback info”].playback.currentTime/ 60) )+ “:” + LEFT_PAD(STRING(FLOOR(outputs[“Get audio playback info”].playback.currentTime % 60)), 2, “0”)

However, some audios are longer than 1 hour long and the formula doesn’t predict this.

As I said, I know it’s very easy for you guys to make this adaptation, but I’m not succeeding.

Can someone help me?

I need to adapt so that it formats the hours right too.

I would suggest using DATETIME formatting function to make your life easier. Try the following:

"Audio Monitoring: " + “\n” + "Total Time: " + FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.duration * 1000), “H:mm:ss”) + " - Current Time: " + FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.currentTime * 1000), “H:mm:ss”)

The formatting string “H:mm:ss” will cause all durations/times to be shown with an hours digit (e.g. 0:00:05 for a 5 second audio). Or you can use just “hh:mm” but it won’t show an hours digit for anything over 59:59. If you want the best of both (only show the hours digit for times an hour or more), then you’ll need to add an IF to each. So…

FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.duration * 1000), “H:mm:ss”)

becomes

IF(outputs[“Get audio playback info”].playback.duration<3600, FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.duration * 1000), “mm:ss”), FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.duration * 1000), “H:mm:ss”))

and a similar treatment for the currentTime

1 Like

Gratitude for the help but it didn’t work. It doesn’t give an error but I have a NULL return from the function. See below:

You need to put a DATETIME() around the numerical value. Check the code again that I shared

Basically, this takes your time value (in seconds), converts it to milliseconds by multiplying by 1000, then DATETIME converts that to a date/time value, and then FORMAT_DATETIME_WITH_TIMEZONE converts that to human readable form. This last part is very flexible and allows you to format in all sorts of ways.

PERFECT!

Very grateful for the help. I certainly didn’t notice the DATETIME function entered the first time, so it didn’t work.

But everything is ok now, everything is working perfectly.

Immense gratitude for the help.

Leo, can you post of pic of what you ended up with, using this formula? thx

This is the flow when the PLAY button is pressed.

First I STOP any audio that is playing and then I create a 100ms DELAY.

The next step is to assign the formula to a text-type variable, using a format where I show the current time and the total time on the screen.

And then I use the stream function {Get audio playback info} to get this information.

The screens are as follows:


And the formula is assigned to the variable like this:

"Audio monitoring\nCurrent time: " + FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.currentTime1000), “H:mm:ss”) + " - Total time: " + FORMAT_DATETIME_WITH_TIMEZONE(DATETIME(outputs[“Get audio playback info”].playback.duration1000), “H:mm:ss”)

I hope it helps you!