So I am new to OOP in general especially with the swing class. My question is that although my code compiles with no error, there is no sound when I play a long sound file of some music. Is there a way to fix this issue because I am using a wave file which is stored in every possible folder I could think of that constitutes to the code. Moreover, is there a specific type of wave format I need since I read some posts about little-endian (I have no clue what that means)...
The code goes to the try block but then "skips" the next four lines as if they were even't there.
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;
public class Sound {
Clip clip = null;
public Sound(String file) {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(file));
clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
System.out.println("Done!");
} catch (Exception err) {
err.printStackTrace();
}
}
}
If possible in layman's terms. Thanks. :)
NOTE: I will like to stress the fact that I do not wish for answers to implement the sun.audio package because it is apparently "outdated" for Java.
EDIT: I found an awkward solution that used a thread loop: as long as the music is playing, the thread will sleep for 15 seconds.