I’m new to Processing and programming overall. I’ve been making this code as part of my mid-term assigment. It consists on making a music player with the help of the Minim library. I cannot write code I haven’t been tought such as “new”, although I did use it once for Minim at the beginning of my sketch, so I cannot really use it.
My biggest concern right now is that I cannot make the music to pause and play from where it stopped, it just rewinds everything. Don’t really know what I did to it, but it was working just 10 minutes ago.
Sorry if I seem like a newbie. Anyways, here is the code:
import ddf.minim.*;
Minim minim;
AudioPlayer jazz1;
//AudioPlayer jazz2;
//AudioPlayer jazz3;
float x;
void setup(){
// setup
noStroke();
size(600,800);
minim = new Minim(this);
jazz1 = minim.loadFile("Overture.mp3");
//jazz2 = minim.loadFile("Too Hip To Retire.mp3");
//jazz3 = minim.loadFile("Whiplash.mp3");
jazz1.play();
}
void draw(){
background(#2F2D2E);
// Bar
fill(#792359);
rect(0,600,600,200);
// Play/Pause Circle
strokeWeight(1);
stroke(#FD3E81);
circle(width/2,700,100);
noStroke();
// Play/Pause Cycle
if (jazz1.isPlaying()==true){
fill(#FD3E81);
rect(width/2-20,675,10,50);
rect(width/2+10,675,10,50);
} else {
// Pause Vector
fill(#FD3E81);
triangle(width/2-15,675,width/2+25,700,width/2-15,725);
}
// Seek Backwards Vector
fill(#FD3E81);
rect(width/2-145,675,10,50);
triangle(width/2-130,700, width/2-90,675, width/2-90,725);
// Seek Forward Vector
fill(#FD3E81);
rect(width/2+135,675,10,50);
triangle(width/2+130,700, width/2+90,675, width/2+90,725);
// Duration Info
x = map(jazz1.position(),0,jazz1.length(),0,width);
strokeWeight(2);
stroke(#FD3E81);
line(0,600,x,600);
noStroke();
}
void mouseReleased(){
// mousePressed for Play Button
if (hoverPlay()==true && jazz1.isPlaying() ){
jazz1.pause();
} else if (hoverPlay()==true && jazz1.position() == jazz1.length() ){
jazz1.rewind();
jazz1.play();
} else if (hoverPlay()==true ) {
jazz1.play();
}
// mousePressed for Backwards Button
if (hoverBack()==true && jazz1.position() < 3000) {
jazz1.pause();
jazz1 = minim.loadFile("Too Hip to Retire.mp3");
jazz1.play();
} else {
jazz1.rewind();
}
}
// Boolean for Play/Pause Button
boolean hoverPlay() {
if (mouseX >= width/2-50 && mouseX <= width/2+50 && mouseY >= 650 && mouseY <= 750){
return true;
} else {
return false;
}
}
boolean hoverBack() {
if (mouseX >= width/2-145 && mouseX <= width/2-90 && mouseY >= 650 && mouseY <= 750){
return true;
} else {
return false;
}
}
boolean hoverForward() {
if (mouseX >= width/2+90 && mouseX <= width/2+145 && mouseY >= 650 && mouseY <= 750){
return true;
} else {
return false;
}
}