# Drag and Drop audio file into Minim

**URL:** <https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123>\
**Category:** Libraries\
**Created:** [November 1, 2019, 4:27pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123 "2019-11-01T16:27:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozman](https://avatars.discourse-cdn.com/v4/letter/o/a88e4f/32.png) [@ozman](https://discourse.processing.org/u/ozman)\
**Post date:** [November 1, 2019, 4:27pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/1 "2019-11-01T16:27:30Z")

</div>

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!

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

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 1, 2019, 8:00pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/2 "2019-11-01T20:00:48Z")

</div>

I think you need to include the drop Event function. See [here](https://forum.processing.org/two/discussion/23713/about-using-drop-library).

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 1, 2019, 11:02pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/3 "2019-11-01T23:02:25Z")

</div>

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

```auto
// _______________________________________________ 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

```

---

<div class="post-metadata">

**Author:** ![ozman](https://avatars.discourse-cdn.com/v4/letter/o/a88e4f/32.png) [@ozman](https://discourse.processing.org/u/ozman)\
**Post date:** [November 1, 2019, 11:37pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/4 "2019-11-01T23:37:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discourse.processing.org/u/ali)\
**Post date:** [May 16, 2021, 8:24pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/5 "2021-05-16T20:24:55Z")

</div>

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.

---

<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:** [May 16, 2021, 8:29pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/6 "2021-05-16T20:29:35Z")

</div>

> [@ali](#):
>
> HI, I know this is a Processing topic, but I would like to do exactly the same but with p5js

Hello,

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

`:)`

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discourse.processing.org/u/ali)\
**Post date:** [May 16, 2021, 8:49pm UTC](https://discourse.processing.org/t/drag-and-drop-audio-file-into-minim/15123/7 "2021-05-16T20:49:11Z")

</div>

I’ll do so.  
Thanks a lot @glv
