This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Problem with the music when exporting

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So, i programmed a little Tetris game. Just a little basic game. The problem, when i export my game to an usable jar, it is not possible to hear any music. But if i test it on eclipse the music works... I tried everything but it still doesnt work... Any idea?
 
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your audio file located - in the same directory/package as the launcher class?

You are catching Exceptions in your main method, but not doing anything if anything if one is caught.  Add a line to printout the exception and see if that provides any clues.
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you seeing any exception being caught in your MusicPlayer class?
 
Fabian Stetter
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Are you seeing any exception being caught in your MusicPlayer class?



The Problem here is, that the music is working fine in eclipse. There is no exception. But when i export my program to an executable jar, the music doesnt work.
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you add a line to printout any exceptions in your launcher class?
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running the executable jar?
 
Fabian Stetter
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Did you add a line to printout any exceptions in your launcher class?



Yea i added the line but there was no exception. And i dont understand your 2nd question? Im just opening the jar with double click
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Fabian Stetter wrote:And i dont understand your 2nd question? Im just opening the jar with double click


I'm not sure what double-click does, but it may be hiding the stack trace printout if an exception is caught.

Try opening a command line window, and launching from the command line.  For example:
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of curiosity, I tried your code on my workstation and did find a potential issue with this line:
   AudioInputStream ais = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(s));

If you read the documentation for AudioSystem#getAudioFileFormat, you will see that it says:

AudioSystem#getAudioFileFormat wrote:The implementation of this method may require multiple parsers to examine the stream to determine whether they support it. These parsers must be able to mark the stream, read enough data to determine whether they support the stream, and, if not, reset the stream's read pointer to its original position. If the input stream does not support these operations, this method may fail with an IOException.


When the application is run from within the IDE, getClass().getResourceAsStream(s) returns an instance of java.io.BufferedInputStream, which does support mark/reset.  

However, when packaged into an executable JAR and run from the command-line (on my workstation with Java HotSpot(TM) 64-Bit Server VM),  getClass().getResourceAsStream(s) returns an instance of sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream, which does not support mark/reset.

When I ran the jarred application from the command-line, I saw this:
If you are finding this same issue, one fix would be to wrap the InputStream returned by getResourceAsStream with BufferedInputStream:

 
Fabian Stetter
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Out of curiosity, I tried your code on my workstation and did find a potential issue with this line:
   AudioInputStream ais = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(s));

If you read the documentation for AudioSystem#getAudioFileFormat, you will see that it says:

AudioSystem#getAudioFileFormat wrote:The implementation of this method may require multiple parsers to examine the stream to determine whether they support it. These parsers must be able to mark the stream, read enough data to determine whether they support the stream, and, if not, reset the stream's read pointer to its original position. If the input stream does not support these operations, this method may fail with an IOException.


When the application is run from within the IDE, getClass().getResourceAsStream(s) returns an instance of java.io.BufferedInputStream, which does support mark/reset.  

However, when packaged into an executable JAR and run from the command-line (on my workstation with Java HotSpot(TM) 64-Bit Server VM),  getClass().getResourceAsStream(s) returns an instance of sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream, which does not support mark/reset.

When I ran the jarred application from the command-line, I saw this:
If you are finding this same issue, one fix would be to wrap the InputStream returned by getResourceAsStream with BufferedInputStream:

Thanks it solved my problem ^^

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!