Good day!
I am doing a game and I want it to have a background sound. I created a class for it and I call it on my main. My code is as follows:
import sun.audio.*;
import java.io.*;
public class Sound {
public void music() {
AudioStream backgroundMusic;
AudioData musicData;
AudioPlayer musicPlayer = AudioPlayer.player;
ContinuousAudioDataStream loop = null;
try {
backgroundMusic = new AudioStream(new FileInputStream("chickendance.wav"));
musicData = backgroundMusic.getData();
loop = new ContinuousAudioDataStream(musicData);
musicPlayer.start(loop);
} catch (IOException error) { System.out.println(error);
}
}
}
This is my main class where i call it.
public class HangmanLauncher extends javax.swing.JFrame {
public HangmanLauncher() {
initComponents();
Sound sound = new Sound();
sound.music();
}
My problem is that the music doesn't play. Error: java.io.IOException: could not create audio stream from input stream.
What does it mean? The type of my file is Microsoft Wave Sound Format and its size is 796kb. May I know what I am doing wrong? Your suggestions will be highly appreciated. Thank you in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…