Posted By:
Daniel_Rosenberg
Posted On:
Monday, July 9, 2001 09:07 AM
Hello, I try to play a sound whose resource is in a JAR but doesn't manage to do it. Here is the core code: JarFile jar = new JarFile(name); Enumeration enum = jar.entries(); while(enum.hasMoreElements()) { ZipEntry entry = (ZipEntry) enum.nextElement(); if ( entry.getName().indexOf("sound") != -1 && !entry.isDirectory() && isSoundFile(entry.getName())) { int beginIndex = entry.getName().lastIndexOf('/'); String entryName = (beginIndex!=-1)?entry.getName().substring(beginIndex+1):entry.getName(); InputStream is = jar.getInputStream(entry); System.out.println("i
More>>
Hello,
I try to play a sound whose resource is in a JAR but doesn't manage to do it.
Here is the core code:
JarFile jar = new JarFile(name);
Enumeration enum = jar.entries();
while(enum.hasMoreElements()) {
ZipEntry entry = (ZipEntry) enum.nextElement();
if ( entry.getName().indexOf("sound") != -1 && !entry.isDirectory() && isSoundFile(entry.getName())) {
int beginIndex = entry.getName().lastIndexOf('/');
String entryName = (beginIndex!=-1)?entry.getName().substring(beginIndex+1):entry.getName();
InputStream is = jar.getInputStream(entry);
System.out.println("is.markSupported()"+is.markSupported());
AudioInputStream ais = new AudioInputStream(is, AudioSystem.getAudioFileFormat(is).getFormat(), 0);
addSound( name, ais);
}
}
public boolean isSoundFile(String s){
return (s!=null)?
(s.endsWith(".au") || s.endsWith(".rmf") ||
s.endsWith(".mid") || s.endsWith(".wav") ||
s.endsWith(".aif") || s.endsWith(".aiff")):false;
}
When I run it, the input stream is not null but I get the exception:
java.io.IOException: mark/reset not supported?
So I cannot create the AudioInputStream.
Any idea would be welcome.
Thanks
Daniel
<<Less