没有测试过的代码。你试试看,有问题告诉我。最好把你的midi文件寄给我,让我试试看。import java.io.*;
import sun.audio.*; class PlayMusic {
AudioStream as;
RandomAccessFile raf;
public void play(String sound, int times) {
try {
raf = new RandomAccessFile("sound/" + sound, "r");
InputStream inStreamObj = new InputStream(){
public int read() throws IOException{
return raf.read();
}
};
as = new AudioStream(inStreamObj);
for (int i = 0; i < times; i++) {
raf.seek(0);
AudioPlayer.player.start(as);
}
}
catch (Exception e) {}
}
}
import sun.audio.*; class PlayMusic {
AudioStream as;
RandomAccessFile raf;
public void play(String sound, int times) {
try {
raf = new RandomAccessFile("sound/" + sound, "r");
InputStream inStreamObj = new InputStream(){
public int read() throws IOException{
return raf.read();
}
};
as = new AudioStream(inStreamObj);
for (int i = 0; i < times; i++) {
raf.seek(0);
AudioPlayer.player.start(as);
}
}
catch (Exception e) {}
}
}
import sun.audio.*; class PlayMusic {
AudioStream as;
RandomAccessFile raf;
public void play(String sound, int times) {
try {
raf = new RandomAccessFile("sound/" + sound, "r");
InputStream inStreamObj = new InputStream(){
public int read() throws IOException{
return raf.read();
}
};
as = new AudioStream(inStreamObj);
for (int i = 0; i < times; i++) {
raf.seek(0);
AudioPlayer.player.start(as);
AudioPlayer.player.join();
}
}
catch (Exception e) {}
}
}