Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  How do I play a sound without using an applet?  (Read 3470 times)
0 Members and 1 Guest are viewing this topic.
Offline sluimers

Senior Newbie




Java games rock!


« Posted 2003-06-03 13:50:55 »

Preferably a .xm or .ogg file Smiley
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2003-06-03 14:56:08 »

You use the javax.sound packages. Look in the JavaDocs.  My GAGESound library may also be of help to you. As for playing OGG, go look at JOrbis. I highly recommend using the Vorbis SPI so that you can use the JavaSound libs instead of the direct Jorbis libs.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline sluimers

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-06-03 16:31:45 »

You mean it's possible to use the javax.sound packages to play a sound without using an applet? I'd sure like to see a simple example. By the way, I can't load your GAGESound library.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2003-06-03 16:46:47 »

Quote
You mean it's possible to use the javax.sound packages to play a sound without using an applet? I'd sure like to see a simple example.


The javax.sound package doesn't work in 1.1 applets, only 1.4. Applets originally used Applet.getAudioClip() until javax.sound was added to give applications and applets more sound control.


Quote
By the way, I can't load your GAGESound library.


Did you put sound.jar in your classpath? You may want to try getting the "LatencyTest" example working before you try doing anything else. If you still have problems, post the error message here and I'll take a look at it.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline sluimers

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-06-03 17:53:14 »

Quote
The javax.sound package doesn't work in 1.1 applets, only 1.4. Applets originally used Applet.getAudioClip() until javax.sound was added to give applications and applets more sound control.


I don't think I've been clear enough. I do not know how to play a sound without using an APPLET.
Meaning using a Frame or a JFrame.
Is that possible?
Because I run into this problem:

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  
import java.applet.*;
import java.awt.*;
import javax.swing.*;

public class SoundFrame extends JFrame{
      private AudioClip snd;
      private JButton play = new JButton("Play");
      private JButton stop = new JButton("Stop");

      public SoundFrame(){
            JPanel buttons = new JPanel();
            buttons.add(play);
            buttons.add(stop);
      }

      public boolean action(Event e, Object o){
      if (e.target == play)
         snd.play();
      else if (e.target == stop)
         snd.stop();
      return true;
   }
      public void loadSound(){
            try{
                  snd = getAudioClip(, "music.au"); // right here, it's in a directory not in a URL
           }
            catch(Exception e){
                  System.err.println("Error loading sound");
            }
      }
}


Quote
Did you put sound.jar in your classpath? You may want to try getting the "LatencyTest" example working before you try doing anything else. If you still have problems, post the error message here and I'll take a look at it.  


Whoops, that's not what I meant. I meant that I can't get even to your website. Page not found.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2003-06-03 18:03:36 »

Quote
I don't think I've been clear enough. I do not know how to play a sound without using an APPLET


Reread what I said. I said that javax.sound provides sound control for applications and Applets alike. i.e. It doesn't care *what* you use. The only API that was applet specific was Applet.getAudioClip().

Quote
Whoops, that's not what I meant. I meant that I can't get even to your website. Page not found.


I just looked at the address. I really managed to mangle that, didn't I? Here's the correct address:

http://java.dnsalias.com

Java Game Console Project
Last Journal Entry: 12/17/04
Offline sluimers

Senior Newbie




Java games rock!


« Reply #6 - Posted 2003-06-04 07:41:37 »

okay, I've tried running your LatencyTest from your soundAPI but I get this error.

Exception in thread "main" java.lang.NoClassDefFoundError: com/dnsalias/java/gag
e/sound/WaveEngine
       at LatencyTest.main(LatencyTest.java:28 )


I tried setting the Classpath, but without succes.

By the way, I've figured out how to play .au files but the sound API doesn't support .xm files, which I want to use as background music.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #7 - Posted 2003-06-04 20:04:35 »

Convert the soudn files to a format that is supported with some other program.  .AU fisn't the greatest format either.  I would just use a standard .WAV unless you require compression... then it seems that the Ogg Vorbis format is the way to go (I haven't used it yet).. check other threads here for more info.

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #8 - Posted 2003-06-04 20:28:26 »

Your error is telling you that your classpath is wrong. Assuming that you are in the same directory as LatencyTest:

java -cp .;..\sound.jar LatencyTest

If you're on Unix, change the semi-colon to a colon and the backslash to a forward slash.

Java Game Console Project
Last Journal Entry: 12/17/04
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 (63 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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