Looping wav without URL and Applet

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?

Solved it :slight_smile:


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();
    }
    
}


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

lol, true! :smiley:

But it works, so I’m happy.

[quote]It seems strange that there’s no easy way to do this… or is there?
[/quote]
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

Thanks very much Toby, I will bear that mind in future, cheers! :wink: