JNLP Java Application won't play audio clips

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1075 Views - Last Post: 30 November 2012 - 02:25 PM Rate Topic: -----

#1 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

JNLP Java Application won't play audio clips

Posted 29 November 2012 - 04:50 PM

Hi everyone! I've searched for hours on the net for an answer to this. I hope you guys can help...

I'm trying to deploy a simple Maze Game Java application (not applet) as a JNLP as instructed by my professor. I've got the program working wonderfully on my system including the sound effects that we have to put in. However, when I run the JNLP file from the web (using a signed JAR), the Maze loads and works correctly, but the sounds clips won't play. The sound files are packaged in the JAR and are contained in the same directory as the class files. I won't post all the code b/c there are a dozen classes and several hundred lines of code, but here is how I implemented the sounds:

	  try{
	    	Clip gong = AudioSystem.getClip();
	    	AudioInputStream inputStream = AudioSystem.getAudioInputStream(Room.class.getResourceAsStream("homer.wav"));
	    	gong.open(inputStream);
	    	gong.start();
	    }catch(Exception e){}



and here is my JNLP

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for MazeGame Application -->
<jnlp
  spec="7.0+"
  codebase="code-base-goes-here"
  href="mazegame.jnlp">
  <information>
    <title>Maze Game</title>
    <vendor>CS602</vendor>
    <description>Maze Game Application</description>
  </information>
  <security>
      <all-permissions/>
  </security>
  <resources>
    <j2se version="1.7+"/>
    <jar href="MazeGame.jar"/>
  </resources>
  <application-desc main-class="maze.SimpleMazeGame"/>
</jnlp> 



I found something with Google regarding a way to include the sound files as resources in the JNLP file and doing something differently in the program like getClass().getResource(), but the post was completely vague and I couldn't get it to work.

Does anyone here know why my sound files won't work when launching the application via JNLP? How do I fix? Thanks ahead of time.

Is This A Good Question/Topic? 0
  • +

Replies To: JNLP Java Application won't play audio clips

#2 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 29 November 2012 - 09:03 PM

No ideas? Suggestions? I'll take anything at this point.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 865
  • View blog
  • Posts: 2,655
  • Joined: 29-July 11

Re: JNLP Java Application won't play audio clips

Posted 29 November 2012 - 09:36 PM

Does the audio file play otherwise? I've noticed that Java is pick about certain audio files, which I assume has something to do with bitrate. Some have played for me, while others have not.
Was This Post Helpful? 0
  • +
  • -

#4 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 07:08 AM

I just ran the JAR file from my computer and it DOESN'T work! It only works in Eclipse! This is a first for me. I included the sound files in the JAR and they are in the correct directory structure for how they are called in the program (same directory as .class files). Again, the sounds are working when I run the application in Eclipse, but they won't play when the program is run from the JAR file (locally) nor in the JNLP (on the web).

Any ideas?

This post has been edited by axnjxn: 30 November 2012 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2832
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 07:26 AM

Please execute the following at the command line in the directory containing the jar file and post the content of the file 'listing.txt'
jar tf MazeGame.jar >listing.txt

This post has been edited by g00se: 30 November 2012 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#6 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 07:40 AM

listing.txt:

META-INF/
META-INF/MANIFEST.MF
maze/Command.class
maze/ding.wav
maze/Direction.class
maze/Door.class
maze/door.wav
maze/homer.wav
maze/MapSite.class
maze/Maze$MazeKeyListener.class
maze/Maze$MazePanel.class
maze/Maze.class
maze/MazeMoveCommand.class
maze/Orientation.class
maze/Room.class
maze/SimpleMazeGame.class
maze/UndoableCommand.class
maze/Wall.class



Also, this exception is occurring when running the JAR file (outside Eclipse). It was displayed thanks to the e.printStackTrace() in the exception handling.

Quote

java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at maze.Room.enter(Room.java:73)
at maze.Door.enter(Door.java:57)
at maze.Maze.move(Maze.java:73)
at maze.MazeMoveCommand.execute(MazeMoveCommand.java:15)
at maze.Maze.doCommand(Maze.java:233)
at maze.Maze$MazeKeyListener.keyPressed(Maze.java:343)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


After searching this on the net, I changed my code to:

  public void openDoor(Maze maze, Room room){
	  maze.setCurrentRoom(room);
	  try{
		  	Clip gong;
		  	InputStream is = this.getClass().getClassLoader().getResourceAsStream("door.wav");
		  	AudioInputStream inputStream = AudioSystem.getAudioInputStream(is);
	    	//AudioInputStream inputStream = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream("door.wav"));
	    	gong = AudioSystem.getClip();
	    	gong.open(inputStream);
	    	gong.start();
	    }catch(Exception e){e.printStackTrace();}
  }



and the new exception that is thrown when the sound should play is:

Quote

java.lang.NullPointerException
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at maze.Room.openDoor(Room.java:84)
at maze.Maze.openDoor(Maze.java:84)
at maze.Maze$MazeKeyListener.keyPressed(Maze.java:336)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


And thanks for taking your time to help me!

This post has been edited by axnjxn: 30 November 2012 - 07:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2832
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 07:44 AM

Quote

After searching this on the net, I changed my code to:

Can you post the package declaration from the beginning of that class please?
Update: please also post, if you can, the url of where the jnlp is deployed

This post has been edited by g00se: 30 November 2012 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#8 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 10:10 AM

package declaration:

package maze;


The JNLP is deployed at http://web.njit.edu/...0/mazegame.jnlp

Thanks again.

This post has been edited by axnjxn: 30 November 2012 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2832
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 10:38 AM

Hmm that's curious. It won't run for me, and throws an exception of a 'spurious' kind. It does run if i download it and run it normally. I suspect it could be something to do with packaging/signing

a. why mark it as 1.7+ ? That could have the effect of restricting it in certain runtimes. Make it as low as possible.
b. there seems no obvious reason for it to be signed. Why did you sign it?
Was This Post Helpful? 0
  • +
  • -

#10 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 10:42 AM

I've classically had problems running JNLP on my school's server if it is unsigned. So I just sign all my JARs that will be run as JNLP

I marked the JNLP file with 1.7+ because the class was created with 1.7 selected in the Eclipse class creation dialog. I was trying to keep everything equivalent. Should I change the JNLP to 1.6?

EDIT: As an additional point, I tried running the JAR locally on my computer (no JNLP) and it DOESN'T play the sounds either! So, there must be a problem with how I am loading the sounds. But I've tried every method I've found on my searches and nothing is making it work.

This post has been edited by axnjxn: 30 November 2012 - 10:43 AM

Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2832
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 11:00 AM

Quote

I've classically had problems running JNLP on my school's server if it is unsigned. So I just sign all my JARs that will be run as JNLP

I think you're mistaken there. jnlp is just a text file. Nothing is 'run' on the server - it runs on the client, which is why it has to be signed to do privileged things. Your maze app doesn't (that i can see)

Quote

I marked the JNLP file with 1.7+ because the class was created with 1.7 selected in the Eclipse class creation dialog. I was trying to keep everything equivalent. Should I change the JNLP to 1.6?
That's logical. But what i'm suggesting is to compile it to a lower version (you could go as low as 1.4) so that as many people as possible can run it.

At what point are the sounds meant to activate? I can't tell otherwise if they're working for me or not
Was This Post Helpful? 1
  • +
  • -

#12 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 11:08 AM

I'll try running unsigned jar file via jnlp. Thanks for the info.

As for the sounds, there is supposed to be a sound when you change 'rooms', open a 'door', or try to go into a wall or closed 'door' (makes Homer's "Doh!" sound).

After inspecting the exception errors that are thrown, it looks like the problem is occurring at this line:

AudioInputStream inputStream = AudioSystem.getAudioInputStream(Room.class.getResourceAsStream("ding.wav"));


It is throwing a Null Pointer Exception

This post has been edited by axnjxn: 30 November 2012 - 11:09 AM

Was This Post Helpful? 0
  • +
  • -

#13 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 11:29 AM

Okay. I got the sounds to work while running JAR file (locally). I haven't tested it over the net via JNLP yet. But for anyone who may be searching Google or DiC for this problem, here's how I got sounds to work from within the JAR:

Clip sound;
AudioInputStream inputStream;
URL url = this.getClass().getClassLoader().getResource("soundfile.wav");
try{
   	inputStream = AudioSystem.getAudioInputStream(url);
    	sound = AudioSystem.getClip();
    	sound.open(inputStream);
    	sound.start();
}catch(Exception e){e.printStackTrace();}



Then, when packing the JAR file, make sure the sound files are in the correct place. My classes were all part of a package called "maze". But since the sound file URL above didn't have any directory information (just the file), my JAR command line looks like this:

jar cvfm MazeGame.jar MANIFEST.MF *.wav maze/*.class

So my sound files were located in the BIN folder where as the class files were located one level deeper in the maze folder.

EDIT: Just to make sure we're all clear, I just tested this and it DOES work with JNLP. The entire problem had to do with how I was loading the files. Eclipse gave me a false sense of accomplishment! Thanks to g00se for his help.

This post has been edited by axnjxn: 30 November 2012 - 11:36 AM

Was This Post Helpful? 0
  • +
  • -

#14 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2832
  • View blog
  • Posts: 12,000
  • Joined: 20-September 08

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 11:40 AM

No, actually your deployed jar's contents were the following. As such there was nothing visibly wrong with your earlier code
META-INF/MANIFEST.MF
META-INF/ME.SF
META-INF/ME.DSA
META-INF/
maze/Command.class
maze/ding.wav
maze/Direction.class
maze/Door.class
maze/door.wav
maze/homer.wav
maze/MapSite.class
maze/Maze$MazeKeyListener.class
maze/Maze$MazePanel.class
maze/Maze.class
maze/MazeMoveCommand.class
maze/Orientation.class
maze/Room.class
maze/SimpleMazeGame.class
maze/UndoableCommand.class
maze/Wall.class


Let me know when you've redeployed and i'll try it again
Was This Post Helpful? 0
  • +
  • -

#15 axnjxn  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 144
  • Joined: 04-February 12

Re: JNLP Java Application won't play audio clips

Posted 30 November 2012 - 12:20 PM

Well, whatever it was, the new code is working in Eclipse, as a JAR file from the command line, and via JNLP over the web.

Here's the link again:
link
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2