2 Replies - 3362 Views - Last Post: 08 November 2012 - 07:20 PM Rate Topic: -----

#1 gfcf14  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 90
  • Joined: 19-January 11

Running an mp3 file (with javazoom's jlayer) from a JAR file probl

Posted 05 November 2012 - 10:12 PM

Hello everybody at dreamincode. I've been trying to convert a java project to an exe file (to cover up the code), and to do so I needed to configure NetBeans (the IDE I use) to create a fatjar instead of a normal one ( http://arnoraps.twea...single-jar.html ), and it worked. Now I converted the fatjar to an exe file using Jar2Exe Wizard. And it works. However, the fatjar only included the java classes and the other jar files I used to read resources (pictures and text files) but not the directory containing the music files (mp3). The exe runs fine when the music folder is in the same address, but I would like to put my music files on a jar to read the music straight from a jar and therefore convert it all to a single fatjar that would be converted to a single executable file, independent of extra folders. I thought I could do this properly because I asked something similar a bit more than a year ago in this topic: http://www.dreaminco...1&#entry1451078 . Here I'm told by a friend to retrieve mp3 files from a JAR file called Music (although I know when getResource() is called it finds the files in a jar regardless of its name), using the following code:

try {
    InputStream is = /*class*/.getResourceAsStream(filename);
    BufferedInputStream bis = new BufferedInputStream(is);
    player = new Player(bis);
}
catch (Exception e) {
    System.out.println("Problem playing file " + filename);
    System.out.println(e);
}



Basically, a Player object would read a BufferedInputStream which reads an InputStream which I believe gets the class name (the class is called MP3) and uses the method getResourceAsStream with the string filename which contains the name of the mp3. It would be like this:

 InputStream is = MP3.class.getResourceAsStream(filename); 


or

 InputStream is = this.getClass().getResourceAsStream(filename); 


or

 InputStream is = getClass().getResourceAsStream(filename); 


When I coded it a year ago, it did the trick. But now that I tried it again I can't get it to work. I always get this error:

 javazoom.jl.decoder.BitstreamException: Bitstream errorcode 102 


Yet this is not a javazoom error! I added

 if(is == null) System.out.println("if is null"); 


after the InputStream is initialization, and every time "if is null" gets printed. So why is it I'm retrieving the mp3 file from Music.jar wrong? (and I have added Music.jar to the libraries folder) please let me know if anyone can help me find the answer to this, and thank you in advance =)

Is This A Good Question/Topic? 0
  • +

Replies To: Running an mp3 file (with javazoom's jlayer) from a JAR file probl

#2 gfcf14  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 90
  • Joined: 19-January 11

Re: Running an mp3 file (with javazoom's jlayer) from a JAR file probl

Posted 07 November 2012 - 02:55 PM

Thank you for all of those who looked at my topic, but after some working around I managed to make it work. While

 InputStream is = /*class*/.getResourceAsStream(filename); 


could have worked before, I'm completely unsure as to what I wrote down for /*class*/ . Trying this:

 InputStream is = ClassLoader.getSystemResourceAsStream(filename);


works wonders with javazoom's jlayer to simply play mp3 files WITHIN a JAR file as library source

I hope this can be useful for anyone who would want to try it out for him/herself
Was This Post Helpful? 0
  • +
  • -

#3 gfcf14  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 90
  • Joined: 19-January 11

Re: Running an mp3 file (with javazoom's jlayer) from a JAR file probl

Posted 08 November 2012 - 07:20 PM

I just tested further, and apparently the code I was given before would have worked, but I was missing a "/" slash:

 InputStream is = MP3.class.getResourceAsStream("/" + filename");

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1