Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 6
  ignore  |  Print  
  Need a really simple library for playing sounds and music? Try TinySound.  (Read 58957 times)
0 Members and 1 Guest are viewing this topic.
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #30 - Posted 2012-03-18 17:35:33 »

Yeah that jar I linked is Javazoom's VorbisSPI Smiley

Offline kuusisto

Senior Duke


Medals: 13



« Reply #31 - Posted 2012-03-18 19:47:39 »

Yeah that jar I linked is Javazoom's VorbisSPI Smiley

I downloaded it twice, but both times the jar appeared to be corrupted.  Regardlesss, I was going to include the jorbis, tritonus-share and vorbisspi libraries separately for the sake of being able to select different versions of each.
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #32 - Posted 2012-03-18 19:50:28 »

Corrupted? The download works fine for me :S

Try this link?

Anyway, my jar is just those three combined together to make distribution easier Grin

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

Senior Duke


Medals: 13



« Reply #33 - Posted 2012-03-18 22:40:41 »

For those following along, you can now load Ogg Vorbis with the help of three pure-Java libraries included with TinySound.

Corrupted? The download works fine for me :S

Try this link?

Anyway, my jar is just those three combined together to make distribution easier Grin
That link worked, thanks.  I still ended up keeping the libraries separate to make it clear what is being included and to allow for different version combinations.
Offline kuusisto

Senior Duke


Medals: 13



« Reply #34 - Posted 2012-03-22 19:04:19 »

I've pushed the Javadocs to the Github pages for the TinySound repository, so it's now easier to see what functionality is available.

For those interested:
Repo https://github.com/finnkuusisto/TinySound
Docs http://finnkuusisto.github.com/TinySound
Offline cubemaster21
« Reply #35 - Posted 2012-04-07 22:54:13 »

I'm working on trying to add sound to my game and i'm casting everything just as it's written in the example. But when I create the sound with the method "kuusisto.tinysound.Sound sound = TinySound.loadSound(filename);" and then call it with "sound.play();" it keeps saying that 'sound' is null and i keep getting a nullpointerexception. Any help with this? Otherwise, everything is beautifully simple.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline kuusisto

Senior Duke


Medals: 13



« Reply #36 - Posted 2012-04-07 23:29:20 »

The loadSound() function returns null if it failed to load.  It's possibly a format thing, but there should be an error message printed to the terminal.  I guess I should say that it will also return null if you haven't yet called the init() function.
Offline cubemaster21
« Reply #37 - Posted 2012-04-07 23:47:13 »

The loadSound() function returns null if it failed to load.  It's possibly a format thing, but there should be an error message printed to the terminal.  I guess I should say that it will also return null if you haven't yet called the init() function.
i call the init() function in the very beginning of the program. do i have to call it in the beginning of that same method or class? As for an error message, all i got was the standard nullpointerexcepiton error.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #38 - Posted 2012-04-07 23:50:39 »

Maybe it's because the file is not found?

Offline kuusisto

Senior Duke


Medals: 13



« Reply #39 - Posted 2012-04-08 04:36:36 »

Maybe it's because the file is not found?

That's probably it.  It looks like I don't print a message if the InputStream that it opens is null.  Make sure your sound file is on the classpath.  Also, you should only specify the file name if you use the load function that takes a String.  If you want to load a sound using a path to the file, you need to use the function that takes a File object.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #40 - Posted 2012-04-08 04:58:45 »

It's best to use getClass().getClassLoader().getResourceAsStream(String), where the String does not start with a forward slash and is relative to the root of the project.

Offline philfrei
« Reply #41 - Posted 2012-04-08 07:04:31 »

Are we getting into the InputStream issues with audio again? I haven't looked at your code, but if you are using a classLoader and getResourceAsStream() method, then you are probably returning an InputStream, and InputStreams often need to have mark/reset capabilities or they throw exceptions, and audio files (e.g. wav files) often don't support this! And part of the problem is in part that it does work under some conditions, but is much less likely to work going forward. ra4king helped me figure out this problem when code of mine worked for his java 1.6, but bombed on his java 7.

If you need to get an AudioInputStream, can I recommend that you use the classLoader to return a URL of a String for your filename? I suspect your code will run more universally that way.

For example, where fileName is a String:
1  
2  
      URL url = YourClass.class.getResource(fileName);
      AudioInputStream ais = AudioSystem.getAudioInputStream(url);


This bypasses the use of an InputStream, circumventing the need for mark/reset capabilities on the file.

I hope I haven't "gone off" on something totally extraneous. Apologies if I have. But when I hear stuff about InputStreams when loading audio, I can't help but think it is this problem. It has been showing up again and again--isn't really well known yet.

"It's after the end of the world! Don't you know that yet?"
Offline cubemaster21
« Reply #42 - Posted 2012-04-08 12:47:46 »

It's best to use getClass().getClassLoader().getResourceAsStream(String), where the String does not start with a forward slash and is relative to the root of the project.
that's probably what i forgot, i was simply putting the source in as a string.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline kuusisto

Senior Duke


Medals: 13



« Reply #43 - Posted 2012-04-08 14:42:22 »

It's best to use getClass().getClassLoader().getResourceAsStream(String), where the String does not start with a forward slash and is relative to the root of the project.
that's probably what i forgot, i was simply putting the source in as a string.
I'm sure you didn't  forget anything.  They're suggesting that TinySound should do this under the hood.

I'm pretty sure it doesn't have to do with mark/reset capabilities.  I don't use those anywhere in my code and I can't find anywhere in the documentation that says an InputStream needs to support them to open AudioInputStreams.  I would assume that the AudioSystem.getAudioInputStream() function taking a URL opens an InputStream under the hood anyway.  The function that takes a String looks like this:
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  
/**
* Load a Music by a resource name. The resource must be on the classpath
* for this to work.
* @param name name of the Music resource
* @return Music resource as specified, null if not found/loaded
*/

public static Music loadMusic(String name) {
    //check if the system is initialized
    if (!TinySound.inited) {
        System.err.println("TinySound not initialized!");
        return null;
    }
    //check for failure
    if (name == null) {
        return null;
    }
    //check for correct naming
    if (!name.startsWith("/")) {
        name = "/" + name;
    }
    InputStream stream = TinySound.class.getResourceAsStream(name);
    //check for failure to find resource
    if (stream == null) {
        System.err.println("Unable to find resource " + name + "!");
        return null;
    }
    return TinySound.loadMusic(stream);
}

I'm reasonably confident he just didn't have the audio file on his classpath or some such.  I've added that null check on the stream with a message last night.
Offline cubemaster21
« Reply #44 - Posted 2012-04-08 15:43:34 »

It goes in the same place as where i put external images, right?

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline kuusisto

Senior Duke


Medals: 13



« Reply #45 - Posted 2012-04-08 16:31:12 »

It goes in the same place as where i put external images, right?
It really depends.  That image directory may not be on your classpath.  Perhaps you should try using the loadSound() function that takes a File first.  It would look something like this:
1  
Sound sound = TinySound.loadSound(new File("path/to/my/file/sound.wav"));
Offline cubemaster21
« Reply #46 - Posted 2012-04-08 16:38:21 »

I've just tried this, and now it's giving me the error :
Error getting resource stream!
mark/reset not supported

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline kuusisto

Senior Duke


Medals: 13



« Reply #47 - Posted 2012-04-08 16:42:51 »

I've just tried this, and now it's giving me the error :
Error getting resource stream!
mark/reset not supported
Well, the just shows that philfrei was right.  Interesting.  I'll have to look into this.  Can I ask what OS you're running and what version of Java you're using?
Offline kuusisto

Senior Duke


Medals: 13



« Reply #48 - Posted 2012-04-08 17:19:25 »

I just now found what philfrei was talking about in the documentation.

From http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream%28java.io.InputStream%29:
Quote
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 operation, this method may fail with an IOException
I've opened an issue on the repo and will try to get it using URLs instead ASAP.  This is system dependent, but it shouldn't be terribly difficult to change.
Offline cubemaster21
« Reply #49 - Posted 2012-04-08 17:36:27 »

I'm running 64 bit Windows 7 with Java 7.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline kuusisto

Senior Duke


Medals: 13



« Reply #50 - Posted 2012-04-08 18:13:04 »

I went ahead and switched it to use URLs as philfrei suggested.  Another option would have been to wrap all InputStreams with BufferedInputStreams, but I like the URL solution.  See if that works for you cubemaster21.
Offline cubemaster21
« Reply #51 - Posted 2012-04-08 19:14:13 »

huzzah!! it works! Thank you very much!

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #52 - Posted 2012-04-08 19:50:43 »

Yeah that was what philfrei and I were talking about in that thread. A change in Java 7 caused AudioSystem to throw that strange mark/reset error when you give it an InputStream from getResourceAsStream(String).

Offline philfrei
« Reply #53 - Posted 2012-05-13 22:05:52 »

I'm curious if TinySound has "matured" to the point where it could be added to the list of Resources on the "Java Gaming Resources" link.

http://www.java-gaming.org/index.php?action=resources
(link directly under the JGO logo)

"It's after the end of the world! Don't you know that yet?"
Offline ReBirth
« Reply #54 - Posted 2012-05-13 23:28:25 »

I'm not waitting for that, I already use it Grin

Offline kuusisto

Senior Duke


Medals: 13



« Reply #55 - Posted 2012-05-14 16:50:59 »

I'm curious if TinySound has "matured" to the point where it could be added to the list of Resources on the "Java Gaming Resources" link.

http://www.java-gaming.org/index.php?action=resources
(link directly under the JGO logo)
I believe it's pretty stable at this point and I would be happy to see it there, but I don't know if it's really my place to make such a decision.  I have one more update that I was planning to push tonight and then I'll just wait for issues to arise (if any).
Offline kuusisto

Senior Duke


Medals: 13



« Reply #56 - Posted 2012-05-27 15:54:18 »

I'm curious if TinySound has "matured" to the point where it could be added to the list of Resources on the "Java Gaming Resources" link.

http://www.java-gaming.org/index.php?action=resources
(link directly under the JGO logo)
Who makes the decision to put things on the list?
Offline Longarmx
« Reply #57 - Posted 2012-05-27 16:55:02 »

I really like this library.  Grin It doesn't have all the features that Paul's has, but it works great! I use this for all of my projects. The interface is really simple and I am going to recommend this library to anyone that needs a simple library for playing sounds and music!

Offline kuusisto

Senior Duke


Medals: 13



« Reply #58 - Posted 2012-05-27 18:24:29 »

I really like this library.  Grin It doesn't have all the features that Paul's has, but it works great! I use this for all of my projects. The interface is really simple and I am going to recommend this library to anyone that needs a simple library for playing sounds and music!
Thanks for the kind words.  I'm glad you like it.
Offline The Cure

Senior Newbie





« Reply #59 - Posted 2012-07-20 11:51:26 »

kuusisto, i'm here to give my feedback about the library. Well, i was looking for a simple library, and when i say "simple", means simple functions, easy and at the same time powerful for my purpose. I tried the "Easy OGG" library, it's a very good library, but in my case i was looking specifically for sound effects, and with the easy ogg library i had no success, cause in sound effects for games we often need to play fast sequences (like a shooter game for example), and the easy ogg isn't good for this (correct me if i'm saying something wrong).

Well, in this case, your library covered everything i needed. At the moment it's working good, no problems or bugs. For sound effects using the .ogg format, is the best that i found. Thank you very much.

"A candle loses nothing by lighting another candle" - Erin Majors
Pages: 1 [2] 3 4 ... 6
  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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!