Hi, I have this code here
import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; public class Playmusic implements Runnable { public static void main(String[] args){ Thread t = new Thread(new Playmusic()); t.start(); } @Override public void run() { AudioInputStream audioIn; try { audioIn = AudioSystem.getAudioInputStream(new File("test.wav")); Clip clip; clip = AudioSystem.getClip(); clip.open(audioIn); clip.start(); Thread.sleep(clip.getMicrosecondLength()/1000); } catch (UnsupportedAudioFileException | IOException | LineUnavailableException | InterruptedException e1) { e1.printStackTrace(); } } }
to play sound on raspberries. But when I run it, it does not produce any output.
I tested it on both Windows and Linux, where it works.
The program does notice the file, though, since it sleeps for the entire duration of the sound and does not give me any Runtime exception.
It also cannot be the speaker causing the problem, because I can play the sound using aplay test.wav and it gives me the result. I wanted to use the JavaFX library, but it seems to be deleted when the java version of resbian is shortened.
source share