Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  My sound file doesn't in a .jar file  (Read 4345 times)
0 Members and 2 Guests are viewing this topic.
Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Posted 2015-12-05 00:44:56 »

My sound in my game will only play if a folder titled res is in the same directory as the .jar file. The res folder is already a source folder in the .jar file here is my code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
try {
           InputStream defaultSound = Game.class.getResourceAsStream("/res/TrailsGameMusic.wav");
           // getClass().getSy.getResource("/images/ads/WindowsNavigationStart.wav");
         
           System.out.println("defaultSound " + defaultSound);  // check the URL!
           AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(defaultSound);
           Clip clip = AudioSystem.getClip();
           clip.open(audioInputStream);
           clip.loop(Clip.LOOP_CONTINUOUSLY);
      } catch (Exception ex) {
           ex.printStackTrace();
      }
Offline Archive
« Reply #1 - Posted 2015-12-05 00:47:19 »

Remove the "/res" part so it just becomes "/TrailsGameMusic.wav"

Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Reply #2 - Posted 2015-12-05 00:57:17 »

Now i dont have sound
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Archive
« Reply #3 - Posted 2015-12-05 02:11:09 »

Now i dont have sound
But is it able to find the file?

Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Reply #4 - Posted 2015-12-05 13:04:58 »

Only when it isnt in a jar file
It just doesn't play as a jar
Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Reply #5 - Posted 2015-12-06 14:32:10 »

It isn't found either
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2015-12-06 17:05:24 »

Use this helper-class to find the appropriate way to find your resource.

http://www.java-gaming.org/topics/faq-cannot-find-the-resource-file/33226/view.html

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline Archive
« Reply #7 - Posted 2015-12-06 18:34:25 »

It isn't found either
Are you packing the resources into the jar file?

Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Reply #8 - Posted 2015-12-06 23:25:28 »

yes
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2015-12-07 07:38:15 »

What is the output of the helper-class?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GamerC4

Senior Newbie


Exp: 4-6 months



« Reply #10 - Posted 2015-12-08 01:00:18 »

It tells me that I am doing it correctly and that is should work

[ClassLoaderDummy] SEARCHING: "/TrailsGameMusic.wav"
[ClassLoaderDummy] FOUND: mislocated resource:
[ClassLoaderDummy]                "TrailsGameMusic.wav"
[ClassLoaderDummy]          in classpath entry:
[ClassLoaderDummy]                "C:\Users\Ciro\Desktop\Trails\Trails.jar"
[ClassLoaderDummy]          for access use:
[ClassLoaderDummy]                getResourceAsStream("/TrailsGameMusic.wav");
defaultSound sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@8938a9
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 com.GamerC4.main.Game.<init>(Game.java:102)
        at com.GamerC4.main.Game.main(Game.java:260)
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2015-12-08 10:02:13 »

java.io.IOException: mark/reset not supported

Just wrap the InputStream in a BufferedInputStream prior to passing it to the AudioSystem:
1  
2  
3  
InputStream defaultSound = Game.class.getResourceAsStream("/TrailsGameMusic.wav");
+ defaultSound = new BufferedInputStream(defaultSound);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(defaultSound);

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

Senior Newbie


Exp: 4-6 months



« Reply #12 - Posted 2015-12-08 22:29:25 »

Thank you
If I can do something to return the favor, let me know
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (581 views)
2019-09-04 15:33:17

hadezbladez (5510 views)
2018-11-16 13:46:03

hadezbladez (2402 views)
2018-11-16 13:41:33

hadezbladez (5772 views)
2018-11-16 13:35:35

hadezbladez (1223 views)
2018-11-16 13:32:03

EgonOlsen (4661 views)
2018-06-10 19:43:48

EgonOlsen (5682 views)
2018-06-10 19:43:44

EgonOlsen (3198 views)
2018-06-10 19:43:20

DesertCoockie (4095 views)
2018-05-13 18:23:11

nelsongames (5115 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04: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!