# Getting file length in minutes with minim

**URL:** <https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555>\
**Category:** Libraries\
**Created:** [July 11, 2020, 6:07pm UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555 "2020-07-11T18:07:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)\
**Post date:** [July 11, 2020, 6:07pm UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555/1 "2020-07-11T18:07:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SouSageYa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sousageya/32/9819_2.png) [@SouSageYa](https://discourse.processing.org/u/SouSageYa)\
**Post date:** [July 11, 2020, 8:20pm UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555/2 "2020-07-11T20:20:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)\
**Post date:** [July 11, 2020, 9:50pm UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555/3 "2020-07-11T21:50:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2020, 10:25pm UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555/4 "2020-07-11T22:25:22Z")

</div>

Here is a simple example with millis():

```auto
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:

> **[print() / Reference](https://processing.org/reference/print_.html)**
>
> The print() function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing. …

> **[println() / Reference](https://processing.org/reference/println_.html)**
>
> The println() function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing…

> **[millis() / Reference](https://processing.org/reference/millis_.html)**
>
> Returns the number of milliseconds (thousandths of a second) since starting the sketch. This information is often used for timing animation sequences.

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:
> 
> - The Processing _website_ has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - The Processing PDE (IDE) has lots to offer!  
> An exploration of the tabs will reveal what is available; libraries, tools and local examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The source code can give insight if you are adventurous:  
> [GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)](https://github.com/processing/processing)  
> Many of the Processing functions are here:  
> [processing/core/src/processing/core/PApplet.java at master · processing/processing · GitHub](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.
> - And the Internet. `:)`

`:)`

---

<div class="post-metadata">

**Author:** ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)\
**Post date:** [July 12, 2020, 7:15am UTC](https://discourse.processing.org/t/getting-file-length-in-minutes-with-minim/22555/5 "2020-07-12T07:15:33Z")

</div>

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

```auto
  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 😃

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!

```auto
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);

```
