So I’m trying to make a music player using the minim library and here is the code:
import ddf.minim.analysis.*;
import ddf.minim.*;
BeatDetect heart = new BeatDetect();
Minim minim;
AudioPlayer file;
FFT fft;
int b1f = 0;
String text = "Nothing";
String theme = "bg (3).jpg";
PImage play;
PImage playPressed;
PImage pause;
PImage previous;
PImage next;
PImage pausePressed;
PImage loop;
PImage loopPressed;
PImage bg;
PImage bg2;
PImage bg3;
PImage bg4;
PImage settings;
PImage settingsPressed;
PImage cross;
PImage crossPressed;
PFont zigBlack;
boolean settingsb = false;
void setup(){
size(600, 400);
minim = new Minim(this);
bg = loadImage(theme);
zigBlack = createFont("Advent Pro Bold", 32);
textFont(zigBlack);
play = loadImage("play.png");
playPressed = loadImage("playPressed.png");
pause = loadImage("pause.png");
previous = loadImage("previous.png");
next = loadImage("next.png");
pausePressed = loadImage("pausePressed.png");
loop = loadImage("loop.png");
loopPressed = loadImage("loopPressed.png");
bg2 = loadImage("bg (2).jpg");
bg3 = loadImage("bg (3).jpg");
bg4 = loadImage("bg (4).jpg");
settings = loadImage("settings.png");
settingsPressed = loadImage("settingsPressed.png");
cross = loadImage("cross.png");
crossPressed = loadImage("crossPressed.png");
file = minim.loadFile("Demons [Imagine Dragons].wav", 1024);
fft = new FFT( file.bufferSize(), file.sampleRate() );
}
void draw() {
background(255,170,0);
stroke(0);
image(bg,0,0,626,417);
image(play,15,10,70,70);
image(pause,65,120,50,50);
image(previous,13,123,45,45);
image(next,122,123,45,45);
image(loop,538,120,50,50);
image(settings,560,10,30,30);
fill(0);
rect(16,90,568,25,10);
fill(255);
textSize(20);
text("Playing: " + text,22,109);
if (mouseX<71 && mouseY<78 && mouseX>15 && mouseY>15) image(playPressed,15,10,70,70);
if (mouseX<106 && mouseY<161 && mouseX>71 && mouseY>123) image(pausePressed,65,120,50,50);
if (mouseX<585 && mouseY<159 && mouseX>547 && mouseY>125) image(loopPressed,538,120,50,50);
if (mouseX<590 && mouseY<36 && mouseX>561 && mouseY>9) image(settingsPressed,560,10,30,30);
fft.forward( file.right );
for(int i = 0; i < fft.specSize(); i++)
{
fill(0);
ellipse(i+300,300,2,fft.getBand(i)+2);
ellipse(-i+300,300,2,fft.getBand(i)+2);
}
if (settingsb == true) {
image(bg,0,0,626,417);
image(cross,5,3,40,40);
fill(b1f);
rect(490,10,100,25,10);
fill(0);
strokeWeight(2);
line(479,10,479,390);
fill(255);
textSize(20);
text("Theme",515,30);
image(bg2,55,100,104,69);
image(bg3,185,100,104,69);
image(bg4,315,100,104,69);
fill(255);
textSize(32);
text("Choose a theme:",140,70);
}
if (settingsb == true && mouseX<40 && mouseY<36 && mouseX>10 && mouseY>9) image(crossPressed,5,3,40,40);
}
void mouseReleased() {
if (settingsb == false && mouseX<71 && mouseY<78 && mouseX>15 && mouseY>15 && file.isPlaying() == false)file.play();
if (settingsb == false && mouseX<106 && mouseY<161 && mouseX>71 && mouseY>123 && file.isPlaying() == true)file.pause();
if (settingsb == false && mouseX<585 && mouseY<159 && mouseX>547 && mouseY>125) file.loop();
if (file.isPlaying() == true) text = "Demons [Imagine Dragons]";
if (file.isPlaying() == false) text = "Nothing";
if (mouseX<590 && mouseY<36 && mouseX>561 && mouseY>9) settingsb = true;
if (settingsb == true && mouseX<40 && mouseY<36 && mouseX>10 && mouseY>9) settingsb = false;
if (settingsb == true && mouseX<199 && mouseY<169 && mouseX>55 && mouseY>100) {
theme = "bg (2).jpg";
bg = loadImage(theme);}
if (settingsb == true && mouseX<289 && mouseY<169 && mouseX>185 && mouseY>100) {
theme = "bg (3).jpg";
bg = loadImage(theme); }
if (settingsb == true && mouseX<419 && mouseY<169 && mouseX>315 && mouseY>100) {
theme = "bg (4).jpg";
bg = loadImage(theme); }
}
You need to downlaod the minim library and these files to run:
https://drive.google.com/drive/folders/185IMGu0IYIR70NybM3xXD8WWTz5MO15A?usp=sharing
What I want to do is basically you drop .wav or .mp3 files to the data folder and it automatically adds them and shows the name of the file in front of “Now Playing:” when a file is playing. You can search through the list with the previous/next buttons (the buttons that the pause button is in between). But I don’t have much of an idea how I could do this or if this is possible. Do I need to use an arraylist?
Thanks.
Also I saw this post which looks like exactly what I need but I ddin’t quite understand how it works: https://forum.processing.org/one/topic/lovely-mp3-player.html