javaaudiojavasoundjavax

JavaZOOM move file after being played


I'm trying to move a file after its being played. I'm using javazoom's basicplayer to play my files and I tried

player.close();
controler.close();
and DSP.close();

and none work

Here is the code I use to play the file

public void play(File sound) {
    if (sound.exists()) {

        new Thread("Sound player") {

            public void run() {

                currentSelectedSound = sound;

                try {
                    control.open(currentSelectedSound);
                    control.play();

                    setVolume(currentAudioVolume);
                    setPan(currentAudioPan);
                } catch (BasicPlayerException e) {
                    e.printStackTrace();
                    System.err.println("Error!");
                }

            }
        }.start();

    } else {
        Logger.logError(TAG, "File doesn't exist!");
    }
}

Solution

  • I'm so happy it finally works, heres the answer for anyone :

                stop();
    
                try {
                    //The thread used to play() the sound
                    soundPlayThread.join();
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
    
    
                //Manually run the garbage collection and yield threads
                System.gc();
                Thread.yield();
    

    I hope no one wastes 6 hours like I just did

    Extreme big thanks to wuppi

    https://stackoverflow.com/a/14123384/3224295