Play wave file out of a jar file
I am trying to play a wave file, which is in a not zipped jar file. I tried the following, it seems to work until byte[]audio = new byte[size], but the size I get is approximatly 2 GB and the wave file is only 130 KB where the wave file is located. And when I want to create the audio, I get a java.lang.OutOfMemoryError: Java heap space Exception.
Code:
JarFile jarFile=null;
try {
jarFile = new JarFile(strJarFileName);
ZipEntry soundFile = null;
soundFile = jarFile.getJarEntry(strWaveFileName);
if(soundFile!=null)System.err.println("sound file is not NULL here");
InputStream is = null;
is = jarFile.getInputStream(soundFile);
BufferedInputStream bis = new BufferedInputStream(is);
if(is!=null)System.err.println("is is NOT NULL");
AudioInputStream audioInputStream=null;
try {
AudioFileFormat aff = AudioSystem.getAudioFileFormat(bis);
audioInputStream = AudioSystem.getAudioInputStream(bis);
AudioFormat af = audioInputStream.getFormat();
int size = (int) (af.getFrameSize() * audioInputStream.getFrameLength());
byte[]audio = new byte[size];
DataLine.Info info = new DataLine.Info(Clip.class, af,size);
bis.read(audio,0,size);
Clip clip;
try {
clip = (Clip)AudioSystem.getLine(info);
clip.open(af, audio, 0, size);
clip.start();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thank's for your help.
Georg