我正在尝试构建一个Java鼓机,该鼓机需要播放各种鼓声部件(低音鼓,军鼓等)的WAV声音样本.因为我需要紧凑地播放声音,所以我需要高性能.目前,我正在使用:
import sun.audio.*;
import java.io.*;
public class MusicPlayer {
private String filename;
public MusicPlayer(String filename) {
this.filename = filename;
}
public void play() {
try {
InputStream in = new FileInputStream(filename);
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
} catch (IOException e) {
e.printStackTrace();
}
}
}
如此处建议:How can I play sound in Java?
虽然它的工作速度比MP3 Javazoom jLayer快,但在高速和我进行cpu密集的工作(如调整应用程序窗口的大小)时,它仍然听起来不稳定.
最佳答案
您是否看过Java Media Framework (JMF):
原文链接:https://www.f2er.com/java/533002.htmlThe Java Media Framework API (JMF)
enables audio,video and other
time-based media to be added to
applications and applets built on Java
technology. This optional package,
which can capture,playback,stream,
and transcode multiple media formats,
extends the Java 2 Platform,Standard
Edition (J2SE) for multimedia
developers by providing a powerful
toolkit to develop scalable,
cross-platform technology.