We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey i want to choose my own mp3 file and i use atm this code here
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;
AudioPlayer Player;
int farbe;
PImage playPause;
PImage hintergrund;
void setup() {
selectInput("Suche einen Song aus","selected");
size(500,400);
background(0);
minim = new Minim(this);
Player = minim.loadFile(path); // Spielt die Mp3 datei ab
Player.loop(); // Wiederholt den aktuellen Song
farbe = 0;
smooth();
playPause = loadImage("play3.jpg");
hintergrund = loadImage("hintergrund2.jpg");
}
void selected(File song){
path = song.getAbsolutePath();
}
void interrupt(){
while(path == null){
noLoop();
}
loop();
}
void draw() {
background(0);
image(hintergrund,0,0);
image(playPause,25,25);
translate(width/2, height/2);
rotate(radians(frameCount % 360 * 2));
colorMode(HSB);
stroke(farbe, 255, 255);
colorMode(RGB);
for(int j = 0; j < 360; j++){
if(Player.mix.get(j)*200 > 50) {
colorMode(HSB);
stroke(farbe, 255,255);
colorMode(RGB);
}
else {
colorMode(HSB);
stroke(farbe,255,255);
colorMode(RGB);
}
line(cos(j)*100, sin(j)*100, cos(j)*abs(Player.left.get(j))*250 + cos(j)*100, sin(j)*abs(Player.right.get(j))*250 + sin(j)*100);
}
//for(int i = 0; i < fft.avgSize(); i++){
//line((i * w)*3, height/1.1, (i * w)*3, height/1.1 - fft.getAvg(i) * 0.5);
farbe += 2;
if( farbe > 255)
{
farbe = 0;
}
// #########MOUSE############
if (mousePressed && (mouseButton == LEFT)) {
Player.pause();
} else if (mousePressed && (mouseButton == RIGHT)) {
Player.play();
}
}
but he says The variable "path" does not exist what should i do to fix this?
Answers
Insert
String path;
just after your imports. You should also consider handling the null case in line 27, in case the user decides to cancel the operation. This is demonstrated in the reference.Kf
Hey i did what you say and i get an error it calls NullPointerExeption Here is my code
I'm not a minim expert, but I see two problems:
selectInput
begins to launch the dialog and the code keeps going -- so your next variable is null because the dialog hasn't run and the callback hasn't fired. The solution is to put the next few lines of code in the callback (see below).everywhere in your code, name your AudioPlayer
player
-- lowercase. This might not be causing an error right now, but calling it Player is a bad idea -- capital names should be class names, and it might be an existing class name in an audio library.Now your draw loop may be giving you an error because
player
is undefined (for the same reason it was in setup). You could handle this in many ways. Two approaches:player
inif
statements and check ifplayer
is null.this has been fixed here:
https://forum.processing.org/two/discussion/20218/visualizer-dont-work