So I've been trying to play sound files using the AudioStream class. It works fine on the first try but doesn't work again after that. Instead, it gives me an IOException error.
Here's the code I used. Note that this code is being ran in a Thread that is executed by an ActionListener form a JButton.
public void run() {
try {
failAudioStream = new AudioStream(failInputStream);
successAudioStream = new AudioStream(successInputStream);
waitingAudioStream = new AudioStream(waitingInputStream);
} catch(IOException e) {
e.printStackTrace();
}
}
This Thread is run by a class implementing ActionListener. Here's the code that I used for that class.
package com.gmail.zacharyvincze.pifiles.listeners;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SendFileListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
(new SendThread()).start();
}
}
As I've said in the begiing, the AudioStream works the first press of the button but on the second press it gives me that error with the following output.
java.io.IOException: could not create audio stream from input stream
at sun.audio.AudioStream.<init>(AudioStream.java:80)
at com.gmail.zacharyvincze.pifiles.listeners.SendThread.run(SendThread.java:36)
java.io.IOException: could not create audio stream from input stream
at sun.audio.AudioStream.<init>(AudioStream.java:80)
at com.gmail.zacharyvincze.pifiles.listeners.SendThread.run(SendThread.java:36)
java.io.IOException: could not create audio stream from input stream
at sun.audio.AudioStream.<init>(AudioStream.java:80)
at com.gmail.zacharyvincze.pifiles.listeners.SendThread.run(SendThread.java:36)
Also, it seems that the AudioStream class in deprecated. So, if you can, could you tell me another way to play audio files in Java?
