javanullpointerexceptioninputstreamioexceptionjavax.sound.midi

NullPointerException while passing an InputStream to Soundbank of MidiSystem in Java


I am trying to create a soundbank by reading from a file and passing it onto the getSoundbank function of MidiSystem. For this purpose, I have to read the file as InputStream for which I tried the following techniques but failed.

First technique -- reading the file using FileInputStream and passing it to the above mentioned function as follows:

InputStream audioSrc = new FileInputStream(file_path);
Soundbank soundbank = MidiSystem.getSoundbank(audioSrc);

It fails with mark/reset exception

Then, I tried the technique mentioned in this thread: java.io.IOException: mark/reset not supported Java Audio Input Stream / Buffered Input Stream

I am faced with java.io.IOException: Resetting to invalid mark exception with BufferedInputStream technique and java.lang.NullPointerException excpetion with url technique. Is there any other technique to overcome the above mentioned exceptions?


Solution

  • Seems like java version 7 discontinued supporting older formats and implemented a new software synthesizer Gervill (http://www.oracle.com/technetwork/java/javase/6u30-relnotes-1394870.html) which has lead to incompatibility between versions 6 and 7(http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#incompatibilities)

    I had been using java version 6 until now and tried loading currently unsupported formats using java version 7 which likely caused these exceptions