File Length .mp3 or .wav with Minim and Processing

Hello guys,

Is Possible to know Which time to complete a sound (music) an .mp3 or .wav of a file in Processing, using the Minim library?

For example, I need at the end of a particular sound, perform a certain action, so I need to know when to finished.

This is the code I used as an example, although I'm using is in another project.

import ddf.minim.*;
Minim minim;

AudioPlayer player[] = new AudioPlayer[3];
String filenames[]   = new String[] {"groove.mp3", "jingle.mp3", "Kalimba.mp3"};

void setup(){
  minim = new Minim(this);
  for(int i = 0; i < 3; i++){
    player[i] = minim.loadFile(filenames[i], 2048);

void draw(){

void keyPressed(){
  int som;

  if (key == 'A' || key == 'a') som = 0;
  else if (key == 'B' || key == 'b') som = 1;
  else som = 2;


void playSom(int opcSom){
  for (int i = 0; i < 3; i++){
    if (player[i].isPlaying()) 

  println("Duration: "); //???

void stop(){
  for(int i = 0; i < 3; i++){


Thanks for attention.


  • Hello GoToLoop,

    Thanks for the feedback ... I will do some testing here ...

    thank you

  • Hello,

    Sorry to still be bothering with it ... looks like it has a problem of "timing" between isPlaying () function, position () and length () the minim library.

    With a file regular work at the end of the sound, I call another normal screen ... with another file did not work, from what I saw, the position did not come reached or exceeded the value of length ().

    I took a look at the documentation, but did not see anything related to time. (As when working with films, for example, validation of the movie works perfect finishes).


    Below is the print which is part of the Code, and values while running the sound.

    Tell if there is any way to control the maximum time and passed, and not the file size?arq1 arq2

    Sorry English, the translator can see that is not cool ... thanks!

  • Hello,

    I managed to solve the problem by comparing the state are playing or not, and a variable to know when the sound began ...

    When the sound is not playing, and the variable is true, it means it will be Feite some other action, and change the variable to false, only returning true when I call the sound again.

    It was only this validation:

     if (!somErro[ultimoSom].isPlaying() && emPausa ){
       emPausa = false;
        //Other action here...

    Thank you and to the next bug ( laughs ...)

Sign In or Register to comment.