Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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  
  Looping wav without URL and Applet  (Read 1481 times)
0 Members and 1 Guest are viewing this topic.
Offline DrQuincy

Junior Member




Vwls hv bn bnnd!


« Posted 2004-02-21 13:13:58 »

Is there any way to loop a .wav file in Java without having to use AudioClip from Applet and URLs.  I want to load the wav from my hard drive not through http.  I've find hundreds of examples on the net but they all use Applet and URL.

It seems strange that there's no easy way to do this... or is there?
Offline DrQuincy

Junior Member




Vwls hv bn bnnd!


« Reply #1 - Posted 2004-02-21 14:05:48 »

Solved it Smiley

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

/**
 *
 * @author  Tim Bennett
 */

public class SoundManager extends JApplet {
    private AudioClip currentMusic;
   
    public SoundManager() {
        try        {
            File file = new File( Globals.RESOURCES_PATH + "sounds\\" + "gameloop.wav" );
            currentMusic = JApplet.newAudioClip( file.toURL() );
        }
        catch (Exception e) {
            System.out.println( e.toString() );
        }
        currentMusic.loop();
    }
   
    public static void main( String[] args ) {
        new SoundManager();
    }
   
}
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #2 - Posted 2004-02-21 14:43:02 »

How is that solving it?  You are still using Applet and URL Smiley

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline DrQuincy

Junior Member




Vwls hv bn bnnd!


« Reply #3 - Posted 2004-02-21 14:45:34 »

lol, true! Cheesy

But it works, so I'm happy.

Offline rreyelts

Junior Member




There is nothing Nu under the sun


« Reply #4 - Posted 2004-02-21 16:01:54 »

Quote
It seems strange that there's no easy way to do this... or is there?

You can always get a URL to a file really easily by using ClassLoader.getResource(). Then you should be able to use the static method, Applet.newAudioClip().

If you want to do this the right way, you should use the javax.sound.sampled.* api. If you read the programmer's guide it should give you enough information to get going. It's definitely more complex than the above method, though.

God bless,
-Toby Reyelts

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline DrQuincy

Junior Member




Vwls hv bn bnnd!


« Reply #5 - Posted 2004-02-21 19:00:33 »

Thanks very much Toby, I will bear that mind in future, cheers! Wink
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.093 seconds with 21 queries.