Drag and Drop audio file into Minim

Hi!

I am trying to implement a drag and drop function into a processing visualizer.

At the moment i am able to play song through my data folder with minim, but i would like to use the Drop library to upload any song and have it play.

Any ideas of how to can combine the two?

Many Thanks!

import drop.*;
import test.*;

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
SDrop drop;
AudioPlayer player;
int pageNumber=1;


void setup(){
  size(1080,720);
  background(255);
  minim = new Minim(this);
  drop = new SDrop(this);
  player = minim.loadFile("audiofile.mp3");
}

void draw(){
  if (pageNumber==1){ // if pagenumber is 1
   player.pause();
  }
  if (pageNumber==2){ // if pagenumber is 2
   player.play();
  }
}
1 Like

I think you need to include the drop Event function. See here.

3 Likes

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

@noel @kll
Thank you both, really appreciate it!
this is be confusing me so much today.

HI, I know this is a Processing topic, but I would like to do exactly the same but with p5js, I have been using the drop function, and is working fine with drag and dropping images, but I cannot figure out how to make it work with audio.

Again I know this is a processing thread but if anyone could help me, I would be really grateful.

Hello,

Start a new topic.
Select p5.js category.
Reference this one if required.

:)

1 Like

I’ll do so.
Thanks a lot @glv

1 Like