After about an hour of googling and trying a ton of different code samples I finally managed to get to the below code which has no errors but it also doesn’t play the audio file; if anyone can see what I’ve done wrong that’ll help.
package Core;
import java.io.InputStream;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class AudioHandler
{
public AudioHandler()
{
InputStream in;
AudioStream as;
try
{
in = this.getClass().getClassLoader().getResourceAsStream("Resources/Sound/grenade.wav");
as = new AudioStream(in);
AudioPlayer.player.start(as);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Most of the other code samples either wouldn’t work with a URL path or they had this weird error “javax.sound.sampled.LineUnavailableException”. So I ended up smashing a bunch of things together to make the above; it doesn’t show any errors at all when compiling/running so I have no idea what could be wrong.