Cant get background music to work?

Hey guys, I made a 2D game, and I can not get the audio to run while playing the game, here is my code for the WAVPlayer class:



package mad.madster.audio;

import java.io.File;

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

import sun.audio.*;

/**
* Plays waveform audio file format audio file formats.
* 
*
*/
public class WAVPlayer implements Runnable {

    /**
     * The {@link Thread} used to play the WAV file.
     */
    private final Thread thread;

    /**
     * The {@link Clip} used to play the WAV file.
     */
    private final Clip clip;

    /**
     * Whether or not the WAV file is being played.
     */
    private boolean playing;

    /**
     * Creates a new {@link WAVPlayer}
     * @param directory The directory of the WAV file.
     * @throws Exception
     */
    
    
    public WAVPlayer (String directory) throws Exception {
        this.thread = new Thread(this);
        this.clip = AudioSystem.getClip();
        this.clip.open(AudioSystem.getAudioInputStream(new File("bkmusic.wav")));
        this.playing = false;
        //backgroundMusic.startMusic();
        WAVPlayer backgroundMusic = new WAVPlayer("bkmusic.wav");
        backgroundMusic.startMusic();
    }

    /**
     * Starts playing the WAV file.
     */
    public void startMusic() {
        playing = true;
        thread.start();
        //backgroundMusic.startMusic();
    }

    @Override
    public void run() {
    	//backgroundMusic.startMusic();
        while (playing) {
            clip.loop(Clip.LOOP_CONTINUOUSLY);
        }
        clip.stop();
    }

    /**
     * Checks whether or not the WAV file is being played.
     * @return Whether or not the WAV file is being played.
     */
    public boolean isPlaying() {
        return playing;
    }

    /**
     * Stops the WAV file from being played.
     */
    public void stop() {
        this.playing = false;
    }

}

Any help?

Have you tried tinysound? Not as good as openal but better than anything I tried.

No, got any links or code to it?

Try searching! ::slight_smile: http://www.java-gaming.org/topics/need-a-really-simple-library-for-playing-sounds-and-music-try-tinysound/25974/view.html

An obvious weirdness in your code would appear to be that the constructor is calling itself.