It appears different service take SPI values in different way....
I tried to write dummy SPI, and load from META-INF/services directory,
works fine.
but for this sample:
http://www.javaworld.com/javaworld/jw-11-2000/jw-1103-mp3.html
I tried the following code to call mp3.jar
import java.io.*;
import javax.sound.sampled.*;
public class A {
public static void main(String[] args) {
String fName = "a.mp3";
new A(fName);
}
public A(String sound) {
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(new
File(sound));
// At present, ALAW and ULAW encodings must be converted
// to PCM_SIGNED before it can be played
AudioFormat format = stream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits()*2,
format.getChannels(),
format.getFrameSize()*2,
format.getFrameRate(),
true); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
System.out.println("\nConverted stream:");
printFormat(format);
}
DataLine.Info info = new DataLine.Info(Clip.class,
stream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
// Add a listener for line events
clip.addLineListener(new LineListener() {
public void update(LineEvent evt) {
if (evt.getType() == LineEvent.Type.STOP) {
System.out.println("Sound stopped.");
System.exit(0);
}
}
});
System.out.println("Playing sound...");
clip.open(stream);
clip.start();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
}
}
}
I always get javax.sound.sampled.UnsupportedAudioFileException: could
not get audio input stream from input file
error. And the class specified in META-INF/services directory never
work.....
I checked com.sun.media.sound.JDK13Services.getProviders method
it appears need priviledge to return values, but I don't know which
priviledge and permission to run that process. And JDK13Services catch
throwable without print any message!!!!!
Any more suggestion?
Thanks.