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]
  ignore  |  Print  
  SOUND  (Read 1006 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2013-08-25 16:48:40 »

how do i add sound in to a java game not a aplet a GAME !!!!

Java freak! Cheesy
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-08-25 17: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
« Reply #2 - Posted 2013-08-25 18:17:48 »

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


Java freak! Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BurntPizza
« Reply #3 - Posted 2013-08-25 18: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 Wizard


Medals: 97
Projects: 4
Exp: 3 years


Extreme Typist.


« Reply #4 - Posted 2013-08-25 19: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.

Offline GNecro1
« Reply #5 - Posted 2013-08-25 19: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)

Java freak! Cheesy
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



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

With what code...
Offline GNecro1
« Reply #7 - Posted 2013-08-25 20:00:31 »

kpars's code !

Java freak! Cheesy
Offline kpars

JGO Wizard


Medals: 97
Projects: 4
Exp: 3 years


Extreme Typist.


« Reply #8 - Posted 2013-08-25 20: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.

Offline GNecro1
« Reply #9 - Posted 2013-08-25 20:13:57 »

THANK YOU SO MUCH Cheesy Cheesy Cheesy: Cheesy Cheesy
I dont know how to thank you Cheesy

Java freak! 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 01: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.

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

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

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

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

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

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

TehJavaDev (60 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 (87 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!