Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  jar support for ogg loader  (Read 2840 times)
0 Members and 1 Guest are viewing this topic.
Offline Jens

Senior Member




Java for games!


« Posted 2003-12-05 19:43:48 »

I noticed that the sound loaders are not "jar friendly" which means they don't try to load a sound file from a jar. I tried to add it. I put the following lines at the beginning of OggLoader.load(String filename):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
        try {
            file = new VorbisFile(filename);
            oggBitStream_ = new FileInputStream(filename);
        } catch (JOrbisException ex) {
            try {
                oggBitStream_ = getClass().getClassLoader().getResource(filename).openStream();
                file = new VorbisFile(oggBitStream_, null, 0);
            } catch (JOrbisException e) {
                throw new IOException(e.getMessage());
            }
        }


This loads from a file and falls back to loading from a jar. A clean implementation should put this in the load(URL) method.

This leads to other problems, although it seams to load the file :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
javax.sound.sampled.LineUnavailableException: Failed to allocate clip data.
        at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:551)
        at com.sun.media.sound.MixerClip.open(MixerClip.java:161)
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setBuffer(SoundSourceImpl.java:82)
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setContainer(SoundSourceImpl.java:100)
        at com.xith3d.scenegraph.View.processSoundNode(View.java:1175)
        at com.xith3d.scenegraph.View.renderNode(View.java:908)
        at com.xith3d.scenegraph.View.renderNode(View.java:991)
        at com.xith3d.scenegraph.View.getRenderFrame(View.java:824)
        at com.xith3d.scenegraph.View.renderOnce(View.java:717)
        at com.xith3d.scenegraph.View.renderOnce(View.java:655)
        at game.Game.run(Game.java:216)
        at game.Game.main(Game.java:270)
java.lang.Error: javax.sound.sampled.LineUnavailableException: Failed to allocate clip data.
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setContainer(SoundSourceImpl.java:103)
        at com.xith3d.scenegraph.View.processSoundNode(View.java:1175)
        at com.xith3d.scenegraph.View.renderNode(View.java:908)
        at com.xith3d.scenegraph.View.renderNode(View.java:991)
        at com.xith3d.scenegraph.View.getRenderFrame(View.java:824)
        at com.xith3d.scenegraph.View.renderOnce(View.java:717)
        at com.xith3d.scenegraph.View.renderOnce(View.java:655)
        at game.Game.run(Game.java:216)
        at game.Game.main(Game.java:270)
Caused by: javax.sound.sampled.LineUnavailableException: Failed to allocate clip data.
        at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:551)
        at com.sun.media.sound.MixerClip.open(MixerClip.java:161)
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setBuffer(SoundSourceImpl.java:82)
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setContainer(SoundSourceImpl.java:100)
        ... 8 more


Anybody knowing what's going on here?

It's not high priority for me, but I'd still be happy to solve this issue.  Smiley

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2003-12-05 21:43:33 »

getResourceAsStream instead of getResource *guessing* Smiley

弾幕 ☆ @mahonnaiseblog
Offline Jens

Senior Member




Java for games!


« Reply #2 - Posted 2003-12-06 07:32:51 »

I wrote openStream(), so this is not a mistake.

Imho it's not that easy. JOrbis isn't jar friendly. They only support loading from a file (filename as String), not from an URL. I tried to work around this by using an InputStream. However this doesn't work for Jars. I made a number of trials and they failed. This means we can't use ogg files, if we need jar files for distribution.  :-/  Does anybody have an idea? Are there other Ogg Vorbis players out there?

I also want to mention that Ogg support is one of the most wished features of the JRE: http://developer.java.sun.com/developer/bugParade/bugs/4499904.html

Xith3D Getting Started Guide (PDF,HTML,Source)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jens

Senior Member




Java for games!


« Reply #3 - Posted 2003-12-06 07:36:23 »

Btw. Unreal Tournament is using Ogg files, too. Grin It's fully documented and patent free, so I don't know why it should not be in the JRE.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2003-12-06 08:11:32 »

>Are there other Ogg Vorbis players out there?

Dunno... but JOrbis is fine Smiley

Cas had used it for AF, too. Therefore the loading from jars just has to work somehow.

Hmyea seems to be also a part of SPGL

Check the source of:
src/com/shavenpuppy/jglib/sound/OggVorbis.java

弾幕 ☆ @mahonnaiseblog
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #5 - Posted 2003-12-06 10:28:19 »

right you are.

The file is here:
http://cvs.sourceforge.net/viewcvs.py/spgl/spgl/src/com/shavenpuppy/jglib/sound/OggVorbis.java?view=markup

1  
2  
3  
4  
5  
6  
7  
            if (url.startsWith("classpath:")) {
                  // Load directly from the classpath
                 input = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(url.substring(10)));
            } else {
                  // Load from a URL
                 input = new BufferedInputStream(new URL(url).openStream());
            }


1  
 * Code in here adapted from JOrbis example code. Thanks guys.


however there is a metric ton of code in that method (fortunatally it is nicly commented Smiley)  It seems odd that that much code is needed just to play an Ogg, I would have thought the OGG API could have abstracted some of it.

Maybe we should just ask princec Smiley

Will.

Offline princec

JGO Kernel


Medals: 368
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2003-12-06 12:55:33 »

Eh?

It Just Works. Don't ask me how it works Wink

Cas Smiley

Offline Jens

Senior Member




Java for games!


« Reply #7 - Posted 2003-12-06 14:34:39 »

I just realised that Cas' and Davids implementation are similar to the example decoder of JOrbis. I don't know why JOrbis didn't abstract this code out.

Anyway, I'm near to having jar support. I have only one issue with calculating the decoded length of the audio output, but I hope I can solve this.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Jens

Senior Member




Java for games!


« Reply #8 - Posted 2003-12-10 07:01:59 »

Jar support for ogg loader is now committed to Xith3D CVS.  :-)

(Testcase for loading an ogg file from a jar added as com.xith3d.test.Xith3DOggLoaderJarTest and demo/ogg_jar_test.jar. Please test.)

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline princec

JGO Kernel


Medals: 368
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2003-12-10 08:20:44 »

It looks like they left it to the likes of us to abstract it out for them. Strange really as it's a really common bit of code I should think.

Something that streams OGGs into an OpenAL double buffered arrangement would be a great addition too. It's not really wise to load a whole 3mb OGG and decompress it into memory to play it...

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #10 - Posted 2003-12-10 08:32:45 »

Quote
Jar support for ogg loader is now committed to Xith3D CVS.  :-)

(Testcase for loading an ogg file from a jar added as com.xith3d.test.Xith3DOggLoaderJarTest and demo/ogg_jar_test.jar. Please test.)


Thanks - nice going.

Just in time for todays xith.org JWS update Grin

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #11 - Posted 2003-12-10 11:34:01 »

JWS online:

http://xith.org/jws/jws-com.xith3d.test.Xith3DOggLoaderJarTest.jnlp

I get an error but that may be my sound setup.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
JavaSound sound driver initialized with 61 availble sources
java.lang.NullPointerException
      at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setContainer(SoundSourceImpl.java:100)
      at com.xith3d.scenegraph.View.processSoundNode(View.java:1184)
      at com.xith3d.scenegraph.View.renderNode(View.java:917)
      at com.xith3d.scenegraph.View.renderNode(View.java:1015)
      at com.xith3d.scenegraph.View.getRenderFrame(View.java:824)
      at com.xith3d.scenegraph.View.renderOnce(View.java:717)
      at com.xith3d.scenegraph.View.renderOnce(View.java:655)
      at com.xith3d.test.Xith3DOggLoaderJarTest.<init>(Xith3DOggLoaderJarTest.java:126)
      at com.xith3d.test.Xith3DOggLoaderJarTest.main(Xith3DOggLoaderJarTest.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at com.sun.javaws.Launcher.executeApplication(Launcher.java:837)
      at com.sun.javaws.Launcher.executeMainClass(Launcher.java:797)
      at com.sun.javaws.Launcher.continueLaunch(Launcher.java:675)
      at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:390)
      at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:199)
      at com.sun.javaws.Launcher.run(Launcher.java:167)
      at java.lang.Thread.run(Thread.java:534)

Offline Jens

Senior Member




Java for games!


« Reply #12 - Posted 2003-12-10 11:57:48 »

The demo needs a file "birds_jar.ogg" (open the ogg_jar_test.jar with e.g Ark to see this). This is a copy of birds.ogg. I had to make a copy, because otherwise you can't know wether it loads the file from the jar or not. birds_jar.ogg is not in your resource.jar. ogg_jar_test.jar is there, but I don't think Java searches for nested jar files.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #13 - Posted 2003-12-10 20:30:51 »

Jens,

I have corrected the problem (changed the jws build task to accommodate for the .jar file) and it now works for me.  

Your improvement is most appreciated by us folk distributing by JWS - thanks.  Now all I need are some sounds Wink

new resource.jar is uploaded - link is as before:
http://xith.org/jws/jws-com.xith3d.test.Xith3DOggLoaderJarTest.jnlp

I'll update the demo/ page soon.

Can you correct the "SoundTest" demo using your new method?  (com.xith3d.test.SoundTest) currently it won't work with JWS.  Currently both other sound demo's listed on xith.org arn't operational.

Cheers,

Will.

Offline Jens

Senior Member




Java for games!


« Reply #14 - Posted 2003-12-11 07:01:13 »

I committed the changed demos to CVS. The joal demo did never work for me.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #15 - Posted 2003-12-11 21:19:00 »

Quote
I committed the changed demos to CVS. The joal demo did never work for me.


now it doesn't load it from the file - can you get it to first try to load it direct and then from a jar if that fails?

Also if you're editing things - a file not found exception (with a message) would be kinder than the current null pointer exception Smiley

1  
2  
java.lang.NullPointerException
        at com.xith3d.sound.drivers.javasound.SoundSourceImpl.setContainer(SoundSourceImpl.java:100)


The joal demo doesn't work here caus I havn't installed joal - maybe I should do that Smiley

Cheers,

Will.

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #16 - Posted 2003-12-12 10:07:16 »

InputStream loading compatibility is also broken now - MediaContainer.java throws NPE at line 94 because of no sound object created for InputStream.

At least WAV loader should be created to maintain compatibility with the older code:

1  
2  
3  
4  
      } else if(inputStream != null) {
          sound = new WavLoader();
          // what do to here?
     }


Anyway, I think we should separate content-type detection mechanism from the node itself to allow pluggable loaders for different sound formats.

I am thinking about generic support for image/sound loading using imageio/sound APIs [this is just an idea, nothing formalized for a moment, and, anyway, additional layer of abstraction that will isolate Xith3D from these APIs would be also good].

Yuri

Yuri Vl. Gushchin
JProof Group
Offline Jens

Senior Member




Java for games!


« Reply #17 - Posted 2003-12-12 10:26:38 »

You're right of course (sorry), although I think it's not a good solution to simple use a WavLoader, if we don't know what the format is. As a simple solution for now, do you think an additional constructor MediaContainer(InputStream inputStream, String format) would do the job (or possibly a constant instead of a string)? Wav could still be the default.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #18 - Posted 2003-12-12 10:34:22 »

Agree on additional constructor.

String should be OK, at least because of TextureLoader also accepts String as image format identifier.

Yuri

Yuri Vl. Gushchin
JProof Group
Offline Jens

Senior Member




Java for games!


« Reply #19 - Posted 2003-12-12 17:24:19 »

Changes are committed now.

It's good that you said this Yuri, because I wanted to ask how to handle format detection with InputStreams anyway. Don't know why I didn't do it. I added also some documentation and error handling. If it is not correct please tell me (via private message if it's a specific thing). Code formatting, error handling and logging conventions would be useful in my opinion.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #20 - Posted 2003-12-12 20:22:12 »

Quote
Changes are committed now.

It's good that you said this Yuri, because I wanted to ask how to handle format detection with InputStreams anyway. Don't know why I didn't do it. I added also some documentation and error handling. If it is not correct please tell me (via private message if it's a specific thing). Code formatting, error handling and logging conventions would be useful in my opinion.


I agree, code formatting error handling and logging convenstions would be a very good thing.  I tried to get a discussion on the topic ages ago in a thread but never really got anywhere.

The code works - but some nitpicking:

* If the file is not found, can a FileNotFoundException be thrown with a message rather than a NPE?  If not FNFE - then some other checked exception because this is really something that needs catching!

* I notice that the code dosn't attempt to load the files relative to the working directory but only the class path.  I guess this isn't a large problem but dual support would be nice.

I wounder if we should setup the sounds like the textures with a register path type of idea?

Just my $0.02

Will.

Offline Jens

Senior Member




Java for games!


« Reply #21 - Posted 2003-12-13 07:53:34 »

Quote
I agree, code formatting error handling and logging convenstions would be a very good thing.  I tried to get a discussion on the topic ages ago in a thread but never really got anywhere.


This probably needs to be discussed in a seperate thread, if more devs cry for it.  Smiley

Quote
* If the file is not found, can a FileNotFoundException be thrown with a message rather than a NPE?  If not FNFE - then some other checked exception because this is really something that needs catching!


A FileNotFoundException is thrown if you pass a wrong filename. What I can imagine you are refering to is when you load an URL using getClass().getClassLoader().getResource("foo.sound"). In this case this returns null if the resource is not found. I can check for a null URL in the constructor of MediaContainer and return an error if this is the case. I agree this would be useful and easy to add. (Disclaimer: This issue was not introduced by my changes in the code. In fact I added a lot of error handling.)

Quote
* I notice that the code dosn't attempt to load the files relative to the working directory but only the class path.  I guess this isn't a large problem but dual support would be nice.


You mean I should load from the current directory when loading an ogg file from an URL? I think is always done unless you explicitly exclude the current directory from your classpath. (Correct me if I understood this wrong.)

Quote
I wounder if we should setup the sounds like the textures with a register path type of idea?


This is a bit more complicated than with textures, because we have different sound loaders, which would have to implement this functionality (because the loading mechanisms are different). But of course it's possible.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #22 - Posted 2003-12-13 09:41:15 »

Quote


A FileNotFoundException is thrown if you pass a wrong filename. What I can imagine you are refering to is when you load an URL using getClass().getClassLoader().getResource("foo.sound"). In this case this returns null if the resource is not found. I can check for a null URL in the constructor of MediaContainer and return an error if this is the case. I agree this would be useful and easy to add. (Disclaimer: This issue was not introduced by my changes in the code. In fact I added a lot of error handling.)


I think that a FNFE would be suitable when that's it's null to avoid a less meningfull NPE.  Sorry to confuse this was just a request, not a comment on your changes Smiley

I don't really care what Exception it is but it should be a) checked and b) carry a message.

Quote

You mean I should load from the current directory when loading an ogg file from an URL? I think is always done unless you explicitly exclude the current directory from your classpath. (Correct me if I understood this wrong.)


Actually it doesn't check the current working directory as far as I can see.

From the demo directory:
java -cp ../libs/xith3d.jar com.xith3d.test.JavaSound NPE's

java -cp ../libs/xith3d.jar:. com.xith3d.test.JavaSound works

The difference in the second is that you are adding the current directory into the classpath which is more friendly with getResource().  So the code only loads the image from the classpath - I was suggesting adding support for the current working directory as well but it's not all that important.

Quote

This is a bit more complicated than with textures, because we have different sound loaders, which would have to implement this functionality (because the loading mechanisms are different). But of course it's possible.


I see, probably a waste of time then.

Cheers,

Will.

Offline Jens

Senior Member




Java for games!


« Reply #23 - Posted 2003-12-13 10:29:30 »

Quote
I think that a FNFE would be suitable when that's it's null to avoid a less meningfull NPE.


I added a check to MediaContainer, which throws an error if you pass null as URL. If this was not what you talked about, then please explain it in more detail. As I said above calling new MediaContainer(getClass().getClassLoader().getResource(foo)) is equivalent to calling new MediaContainer((URL) null), if the resource foo is not in your classpath.

Quote

Actually it doesn't check the current working directory as far as I can see.

From the demo directory:
java -cp ../libs/xith3d.jar com.xith3d.test.JavaSound NPE's


That's what I meant with "explicitly excluding the current directory". Usually the "." has to be there, if you specify the classpath and want to have the current directory in it. If you don't specify a classpath loading from the current directory works. Anyway, if you want to have support for it you need to change the Java core, because the Ogg Loader only gets an URL and doesn't search for resources.  Smiley

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #24 - Posted 2003-12-13 21:00:17 »

I would have prefered a FNFE since it is checked and would force anyone calling the contructor to catch it.  I understand this is an API change and may make some people unhappy so it's probably best you didnt' do it now.

Let me ask you this: Do you want your application bombing out just because it couldn't find a particular sound?  I would think in most cases - no you wouldn't.  Of course you can always catch the FNFE and exit if this is what you would like.

Unchecked exceptions are best used when the programmer has made a mistake.  It's reasonable I think that in some cases you may try to play an ogg that doesn't exist (think if you were creating a  3D Java ogg sound player and the user can play arbituary files)

Again - just my $0.02  perhaps I should submit an RFE so that people can vote on it - it may cause a small amount of code changes.

As for the current directory - it would be possible to construct the URL by getting the current directory from "new File (.)" (rather than using the classpath) but it really doesn't matter.  If I need that function I'll code it myself Grin  It's better practice to use the class path anyway.

Will.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (12 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!