Drag and Drop audio file into Minim

yes @noel thanks, looks good
i tested mixing 2 examples:

//_______________________________________________ Minim lib
import ddf.minim.*;
Minim minim;
AudioPlayer player;
boolean isLoaded=false;

//_______________________________________________ Drop lib
import drop.*;
SDrop drop;
MyDropListener m;

void setup() {
  size(512, 200);
  minim = new Minim(this);
  drop = new SDrop(this);
  m = new MyDropListener();
  drop.addDropListener(m);
}

void draw() {
  background(200, 200, 0);
  if ( isLoaded ) {
    if ( player.isPlaying() )
      text("Press any key to pause playback.", 10, 20 );
    else
      text("Press any key to start playback.", 10, 20 );
  }

  //else
  m.draw();
}

void keyPressed() {
  if ( player.isPlaying() )
    player.pause();
  else if ( player.position() == player.length() ) {
    player.rewind();
    player.play();
  } else
    player.play();
}

void dropEvent(DropEvent theDropEvent) {
}

class MyDropListener extends DropListener {  // a custom DropListener class.
  int myColor, x, y, w, h;

  MyDropListener() {
    myColor = color(255);
    x =10; 
    y=height-110;
    w=100;
    h=w;
    setTargetRect(x,y,w,h);         // set a target rect for drop event.
  }

  void draw() {
    push();
    fill(myColor);
    rect(x,y,w,h);
    fill(0);
    textSize(20);
    text("DROP", x+20, y+60);
    pop();
  }

  void dropEnter() {
    myColor = color(255, 0, 0);
  }

  void dropLeave() {
    myColor = color(255);
  }

  void dropEvent(DropEvent theEvent) {
    println("Dropped on MyDropListener");
    println("isFile() \t"+theEvent.isFile()+"\nisURL() \t"+theEvent.isURL());

    print("### loading file ");
    if ( theEvent.isFile() ) {
      //File myFile = theEvent.file();
      String myFile = theEvent.toString();
      println(myFile);
      player = minim.loadFile(myFile);
      isLoaded = true;
    }
  }
} // end class

3 Likes