Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  Paulscode loading from InputStream?  (Read 18022 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Radirius Software Developer


« Posted 2014-01-26 04:05:42 »

Is it possible to load a sound and play it from an inputstream? I want to be able to access from within and outside the jar.

Offline gouessej
« Reply #1 - Posted 2014-01-26 21:03:48 »

Yes, it is, I do that in the pre-beta version of TUER. I use Paul Lamb Sound Library with its JOAL plugin.

Offline philfrei
« Reply #2 - Posted 2014-01-26 22:09:08 »

Yes, as gouessej say, can do with Paul's library.
Can also be done with TinySound.
Can also be done with straight javax.sound.sampled.

However, in the latter case, you use AudioInputStream, not InputStream. InputStream has requirements for the file (e.g., Marking, Resetting) that are usually not met by audio data files.

I'm assuming you just meant input streaming in a general sense, weren't referring to the specific Java class InputStream.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2014-01-26 22:14:31 »

InputStream has requirements for the file (e.g., Marking, Resetting) that are usually not met by audio data files.

I'm assuming you just meant input streaming in a general sense, weren't referring to the specific Java class InputStream.

InputStream methods mark() and reset() only have to provide their described functionality, if markSupported() returns true, which by default it does not.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Radirius Software Developer


« Reply #4 - Posted 2014-01-26 22:45:10 »

Well, where might I find this elusive AudioInputStream method? I am on a LWJGL binding, if it matters.

Sorry if this is a stupid question, I just could not for the life of me find it in here

Offline philfrei
« Reply #5 - Posted 2014-01-27 04:42:28 »

AudioInputStream is part of javax.sound.sampled. I can't recall how Paul has us load sounds. It's been a couple years since I looked at his library. I've just been using methods based on javax.sound.sampled.

I've been wondering, too, how to do what you are asking about, using LWJGL or LibGDX. My system is too slow to implement Android emulation, so I haven't tested sound coding in that context. But I also wonder if LWJGL & Libgdx make use of javax.sound.sampled for their implementation. I recall someone writing somewhere that this was true, but my memory is shaky and I could have it totally wrong.

Looking at this tutorial: http://www.lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source
something called WaveData is used for loading a sound. By its syntax, it seems to me you could load either from within the jar or not, according to the usual rules of addressing files. But I haven't tested it.


InputStream has requirements for the file (e.g., Marking, Resetting) that are usually not met by audio data files.

I'm assuming you just meant input streaming in a general sense, weren't referring to the specific Java class InputStream.

InputStream methods mark() and reset() only have to provide their described functionality, if markSupported() returns true, which by default it does not.

Ah, I was being sloppy. Further clarifying, according to the comments in the api for AudioSystem.getAudioInputStream(InputStream inputStream)  http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream%28java.io.InputStream%29, this method for loading a file may or may not run the tests Riven mentions. For this reason, I use a URL for the input parameter instead of an InputStream. But some folks prefer to wrap the InputStream in a BufferedInputStream, and this also works.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2014-01-27 07:13:41 »

I'd consider the implementers of
getAudioInputStream(InputStream stream)
sloppy. They should simply have wrapped their InputStream parameter in a BufferedInputStream as part of their implementation, and not put the burden on the callsite. I mean, java.awt.image.ImageIO also uses multiple parses/loaders to make an attempt at loading the file, and does this marking/reseting behind the scenes.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gouessej
« Reply #7 - Posted 2014-01-27 13:25:01 »

Sorry if this is a stupid question, I just could not for the life of me find it in here
Class.getResource() returns a URL that you can pass to paulscode.sound.SoundSystem.loadSound(URL,String). I use this method to load my sound samples from JARs.

Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Radirius Software Developer


« Reply #8 - Posted 2014-01-27 23:07:10 »

So, with getResource(), it's relative location was in the classpath root, right? What if I want to get a resource outside the jar?

Offline philfrei
« Reply #9 - Posted 2014-01-27 23:56:23 »

If you know the location of the jar, you can just use it directly.

If not, the following is one technique:

1  
System.getProperty("user.dir");

Nice list of various properties here:
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties%28%29

Here is another method:
1  
2  
     URL url = Location.class.getProtectionDomain()
        .getCodeSource().getLocation();

I've never tried it, but when I did a search, this came up numerous times.
(Search I did was: java find jar location)

With file access outside of the jar, there may be permission issues.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #10 - Posted 2014-01-28 00:47:54 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public static String jarDir()
{
   try
   {
      return (new File(SomeClass.class.getProtectionDomain().getCodeSource().getLocation().toURI())).getParent();
   }
   catch(URISyntaxException e)
   {
      e.printStackTrace();
      return null;
   }
}


Will return the directory containing the jar file.

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.

E.R. Fleming (15 views)
2014-07-29 03:07:13

E.R. Fleming (5 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!