I'm using the Minim 2.2.0 library with JAVA. The library requires us to define a helper class defining two methods and pass an object of this class to the Minim constructor. I wrote the MinimHelper class as follows.
public class MinimHelper {
String sketchPath( String fileName ) {
return "C:\\Users\\Martin\\Downloads\\"+fileName;
}
InputStream createInput(String fileName) {
InputStream is = null;
try{
is = new FileInputStream(sketchPath(fileName));
}
catch(Exception e){
System.out.println(e.toString());
}
return is;
}
}
And I wrote my main as follows
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
AudioPlayer player;
Minim minim = new Minim (new MinimHelper());
player = minim.loadFile("Butterfly.mp3");
player.play();
}
}
However, I'm getting the following error in the console.
==== JavaSound Minim Error ====
==== Couldn't find a sketchPath method on the file loading object provided!
==== File recording will be disabled.
==== JavaSound Minim Error ====
==== Couldn't find a createInput method in the file loading object provided!
==== File loading will be disabled.
==== JavaSound Minim Error ====
==== Error invoking createInput on the file loader object: null
Exception in thread "main" java.lang.NullPointerException
at ddf.minim.javasound.JSMinim.getAudioRecordingStream(Unknown Source)
at ddf.minim.Minim.loadFile(Unknown Source)
at ddf.minim.Minim.loadFile(Unknown Source)
at Main.main(Main.java:9)
Please tell me where I'm doing wrong.
I think the sketchPath()
and createInput()
functions need to be public
for Minim to be able to find them.
Going through the source, Minim eventually calls Class.getMethod()
to get the functions you've defined. From the Java API (emphasis mine):
Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object.
If that's not the problem: Make sure the Butterfly.mp3
file is where you're telling it to look.
Does C:\\Users\\Martin\\Downloads\\Butterfly.mp3
exist? Does it have the correct permissions?
For more information, you might try adding print statements inside your MinimHelper
class. Are the functions being called? What are the values being passed to it?