I find slightly wrong to have three different things with the same name: the class name (by tradition, we prefer uppercase initial for class names), the variable of same type, and a field inside the class... Perhaps that's not a problem at Java level, but it feels confusing. The alone song word in play() is strange too... And, well, you should keep the size() call in setup().
Ok I changed that now im getting NullPointerException with the song = minim.loadFile("12.wav"); line. And with the super.stop(); im getting "the function stop() does not exist.
Ok i moved the Song = minim loadFile('12.wav'); into global, but now i get the error "Badly formed character constant." I found this post that talked about it was it supposed to of been fixed in 1.5.1 or in 2.0?
import ddf.minim.*; //import processing.core.*;
class Song { Minim minim; AudioPlayer Song; Song = minim.loadFile('12.wav');
Song() { }
void play() {
// this loads mysong.wav from the data folder Song.play(); }
void draw() { background(0); }
void stop() { Song.close(); minim.stop();
// super.stop(); } }
Edit: here is what im getting in the debug console.
processing.app.SketchException: Badly formed character constant at processing.mode.java.preproc.PdePreprocessor.checkForUnterminatedMultilineComment(PdePreprocessor.java:266) at processing.mode.java.preproc.PdePreprocessor.write(PdePreprocessor.java:299) at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:261) at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197) at processing.mode.java.JavaBuild.build(JavaBuild.java:156) at processing.mode.java.JavaBuild.build(JavaBuild.java:135) at processing.mode.java.JavaMode.handleRun(JavaMode.java:176) at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481) at java.lang.Thread.run(Thread.java:722)
I figured it out the it was starting the song then immediately stopping it, but now the song doesn't sound right. It sounds slowed and distorted. What could I do to fix that.
I reduced the frameRate to 1 and now it sounds better but now i noticed it's starting the file twice about 1 - 2 seconds later. What could be causing this?
I figured out the stopping issue.
import ddf.minim.*; AudioPlayer music; Minim minim; Song Song;
void setup () { size(100, 100); frameRate(1); Song = new Song(); minim = new Minim (this); }
I am not a specialist of Minim, in general you should take a look at the examples of Processing to see how things are done. But I don't think you should call play() on each frame. You are supposed to call it only once, at least until the sequence ends.
I reduced the frameRate to 1 and now it sounds better but now i noticed
it's starting the file twice about 1 - 2 seconds later. What could be
causing this?
It won't start playing until the next frame is drawn which will take up to a second if you've set the frameRate to 1. Also PhiLho is correct - you don't want to be calling play() every frame, call it when frameCount == 1 or set a boolean to prevent repeated calls (I think you can call from setup() which gets round all this but I can't test that at the moment).
Generally speaking if you're having to do something like setting the frameRate extremely low to get things working there's something wrong with your design.