Getting file length in minutes with minim

The length() function gives it in miliseconds as an integer so dividing doesn’t work. Did some research but couldn’t find anything and it seems like there is no other function similar to length().
Can somebody help?

Can you explain your problem better please. What do you actually want to divide/trim

I want to get the length of the audio file in ‘minute : seconds’ format with minim. The length() function gives the length of the audio file already but in miliseconds as an integer so didn’t have much luck using that.

1 Like

Here is a simple example with millis():

int ms;
int sec;
int min;
int hours;
int days;

int offset;

void setup() 
  {
  }

void draw() 
  {
  background(0);
  ms = millis();
  print(ms);
  println(" ms");
  
  sec = ms/1000;
  print(sec);
  println(" sec");

  print(sec); print(":"); println(ms);
  
  //min = sec/?;

  /*
  Complete the rest for:
  hours
  days
  */
  }

I kept it as simple as possible.

References:

One of the best tools in a programmers tool chest is knowing the resources available to you and learning to navigate and use them.

This is a very short list:

Resources < Click here to expand !

I encourage you to review the resources available here:

:)

4 Likes

Thanks a lot! With a few additions it works great:

  fill(0);
  int sec = file2.length() / 1000;
  int min = sec / 60;
  sec = sec - min * 60;
  if (sec < 10) text(min + ":0" + sec,250,250);
  else text(min + ":" + sec,250,250);

it was much simpler than I thought, I was overcomplicating it in my head :smiley:

I know those resources, they help everyday!. Especially older forum posts.

Edit:
And the duration and time left is working beatifully now thanks so much!

fill(255);
  int sec = file2.position() / 1000;
  int min = sec / 60;
  sec = sec - min * 60;
  if (sec < 10) text(min + ":0" + sec,12,380);
  else text(min + ":" + sec,12,380);
  
  fill(255);
  int sec2 = (file2.length() - file2.position()) / 1000;
  int min2 = sec2 / 60;
  sec2 = sec2 - min2 * 60;
  if (sec2 < 10) text(min2 + ":0" + sec2,560,380);
  else text(min2 + ":" + sec2,560,380);
2 Likes