Question: I can’t figure out how to add music to my java replit project
My code plays music fine on Eclipse, probably since that runs on my local machine. But I don’t know how to add it for Replit. All the resources, including the tutorial provided by replit, are for python. But I am using java.
Repl link: https://replit.com/@NikhilGarg7/Java-Project?v=1
This is my code for the music itself
import java.io.File;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;
public class musicStuff
{
void playMusic(String musicLocation)
{
try
{
File musicPath = new File(musicLocation);
if(musicPath.exists())
{
AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.addLineListener(event ->
{
if(LineEvent.Type.STOP.equals(event.getType()))
{
clip.close();
}
});
//JOptionPane.showMessageDialog(null, "Press OK to stop playing");
} else
{
System.out.println("Can't find file");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
This code is in my main class which is actually playing the music.
String filepath = "BetterCallSaul.wav";
musicStuff musicObject = new musicStuff();
musicObject.playMusic(filepath);
This is the error that happens when I try to run it
Im a beginner to java so im sorry if im missing something haha. Thank yoiu