I have a problem with my code where each time I run the project, this is thrown. Now I have narrowed it down to that the sound does play when I call the play() method but does not when I call the playL() method.
package net.chrypthic.Ball;
import sun.audio.*;
import java.io.*;
public class SoundManager {
AudioPlayer ap = AudioPlayer.player;
AudioStream as;
ContinuousAudioDataStream loop = null;
public SoundManager(String music)
{
try
{
InputStream input = new FileInputStream("./"+music);
as = new AudioStream(input);
AudioData ad = as.getData();
loop = new ContinuousAudioDataStream(ad);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void play()
{
ap.start(as);
}
public void stop()
{
ap.start(as);
}
public void playL()
{
ap.start(loop);
}
public void stopL()
{
ap.start(loop);
}
}
Why? I pass sound/gsong1b.wav to it which has a size of 6.2MB, is 2 minutes long and has a bit rate of 16000Hz. I have heard that sounds have to be less that 4mb big but it plays, and only errors when I loop.... Any Help would be greatly appreciated.
Those classes you use (AudioPlayer, AudioStream), even though they are from the official Java JDK, are in fact reserved classes, meaning that Oracle (and Sun before them) reserves the right to change them without notice. You should use the official sound API instead:
Using an IDE goto Action performed metthod of your sound button. For continuous playing of .wav files. I have use the following code and it works fine using thread. Make sure you import thev following. import sun.audio.; and import java.io.;
Have a try with HeadspaceMixer instead. javax.sound is not a completed implementation.