Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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  
  SOUND  (Read 713 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1

Senior Member


Medals: 1
Projects: 3



« Posted 2013-08-25 18:48:40 »

how do i add sound in to a java game not a aplet a GAME !!!!
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-08-25 19:09:44 »

Applets and games are two different things Wink
Applets are how you display what you make in Java. Games are an example of what you make in Java.
Anyways, from what I've heard java sound is hard to work with so check out TinySound.
Offline GNecro1

Senior Member


Medals: 1
Projects: 3



« Reply #2 - Posted 2013-08-25 20:17:48 »

NO I NEED IT NOW I DONT WANT LIBS I AM WORKING ON A LUDUM DARE GAME

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BurntPizza
« Reply #3 - Posted 2013-08-25 20:20:38 »

NO I NEED IT NOW I DONT WANT LIBS I AM WORKING ON A LUDUM DARE GAME



Maybe you should of thought this out before hand.

Besides, TinySound seems to be pretty much plug and play in less then 5 minutes, certainly better than figuring out Java Sound.
Offline kpars

JGO Ninja


Medals: 57
Projects: 4
Exp: 2 years


Kemoy Labs/Radirius Game/Engine Developer


« Reply #4 - Posted 2013-08-25 21:28:47 »

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  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
package net.kemoy.gui;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class Sound {
   public static Sound music = loadSound("/music.wav");
   public static Sound break_tile = loadSound("/break.wav");
   public static Sound pickup = loadSound("/points.wav");
   
   private Clip clip;

   public static Sound loadSound(String fileName) {
      Sound sound = new Sound();
      try {
         AudioInputStream ais = AudioSystem.getAudioInputStream(Sound.class
               .getResource(fileName));
         Clip clip = AudioSystem.getClip();
         clip.open(ais);
         sound.clip = clip;
      } catch (Exception e) {
         System.out.println(e);
      }
      return sound;
   }

   public void loop(final int delta) {
      try {
         if (clip != null)
            new Thread() {
               public void run() {
                  synchronized (clip) {
                     clip.stop();
                     clip.setFramePosition(0);
                     clip.loop(delta);
                  }
               }
            }.start();
      } catch (Exception e) {
         e.printStackTrace();
         System.exit(0);
      }
   }

   public void play() {
      try {
         if (clip != null)
            new Thread() {
               public void run() {
                  synchronized (clip) {
                     clip.stop();
                     try {
                        Thread.sleep(45);
                        clip.setFramePosition(0);
                        clip.start();
                     } catch (InterruptedException e) {}
                  }
               }
            }.start();
      } catch (Exception e) {
         e.printStackTrace();
         System.exit(0);
      }
   }
}


This will work fine as long as you don't have too many sounds going on at once.

"Living is easy with eyes closed, misunderstanding all you see. It's getting hard to be someone, but it all works out." ¤¤ Kemoy Labs: http://www.kemoy.net/
Offline GNecro1

Senior Member


Medals: 1
Projects: 3



« Reply #5 - Posted 2013-08-25 21:53:11 »

i get this error
1  
2  
3  
4  
5  
6  
7  
8  
9  
java.lang.NullPointerException
   at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
   at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
   at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
   at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
   at Sound.loadSound(Sound.java:14)
   at Sound.<clinit>(Sound.java:7)
   at Main.<init>(Main.java:42)
   at Main.main(Main.java:153)
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-08-25 21:57:45 »

With what code...
Offline GNecro1

Senior Member


Medals: 1
Projects: 3



« Reply #7 - Posted 2013-08-25 22:00:31 »

kpars's code !
Offline kpars

JGO Ninja


Medals: 57
Projects: 4
Exp: 2 years


Kemoy Labs/Radirius Game/Engine Developer


« Reply #8 - Posted 2013-08-25 22:01:52 »

That means the file is not found.

Try messing with the separators, so instead of "/res/music.wav" it would be "res/music.wav", or vise-verse.

"Living is easy with eyes closed, misunderstanding all you see. It's getting hard to be someone, but it all works out." ¤¤ Kemoy Labs: http://www.kemoy.net/
Offline GNecro1

Senior Member


Medals: 1
Projects: 3



« Reply #9 - Posted 2013-08-25 22:13:57 »

THANK YOU SO MUCH Cheesy Cheesy Cheesy: Cheesy Cheesy
I dont know how to thank you Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #10 - Posted 2013-08-26 03:29:55 »

Im going to say thank you aswell ive been searching for this all day.excellent work my friend excellent.
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.

xsi3rr4x (11 views)
2014-04-15 18:08:23

BurntPizza (10 views)
2014-04-15 03:46:01

UprightPath (23 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (107 views)
2014-04-08 23:06:04

tom_mai78101 (207 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!