We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey i got a problem with my visualizer
When i use this code I can select a MP3 file but the Visualizer didn´t show the line and only play the Sound
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
String path;
Minim minim;
AudioPlayer Player;
int farbe;
PImage playPause;
PImage hintergrund;
void setup() {
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){
loop();
}
noLoop();
}
void draw() {
selectInput("Suche einen Song aus","selected");
interrupt();
background(0);
Player = minim.loadFile(path); // Spielt die Mp3 datei ab
Player.play();
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 when i use this code Visualizer show me lines and effects why? here the visualizer got a MP3 in the loadFile but i need a way to choose the mp3 file
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
String path;
Minim minim;
AudioPlayer Player;
int farbe;
PImage playPause;
PImage hintergrund;
void setup() {
size(500,400);
background(0);
minim = new Minim(this);
Player = minim.loadFile("bla.mp3"); // 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){
loop();
}
noLoop();
} */
void draw() {
//selectInput("Suche einen Song aus","selected");
//interrupt();
background(0);
// Player = minim.loadFile(path); // Spielt die Mp3 datei ab
// Player.play();
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();
}
}
Please help me guys i need the filepath way for my university plx plx plx :(
Answers
selectInput shouldn't be in draw(). draw() is called 60 times a second.
similarly don't load anything in draw(). calling loadFile() 60 times a second is ridiculous. load it in setup(). make it a global variable, like the example does.
Hey selectInput is now in setup() my visualizer is still freezing and lines are not showing up
what do you mean with global variable
greetings
ok, it's already global
line 10 defines an AudioPlayer (call this player rather than Player, capitalised names in java are used for classes, not members)
this is outside of setup() and any other method so it is global
the working version loads the file in setup(). you want the user to pick a file so you need some logic in there to stop everything until he has. this is further complicated by the fact that the user can dismiss the selection box...
something like this?
i did what you say and an error shows up called NullPointer Exception
ah, yes, player can be null there. the draw() loop doesn't stop just because i call noLoop(), it only stops after the current call.
add a
return;
after line 38. that way draw() WILL stop if player is still null.btw ctrl-t in the editor will indent it nicely.
if code is hard to read it's harder to debug.
fixxed the problem here is the working code
I arranged your code a bit. You will need to change the name of your image files
Kf