Java:播放WAV声音

前端之家收集整理的这篇文章主要介绍了Java:播放WAV声音 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试构建一个Java鼓机,该鼓机需要播放各种鼓声部件(低音鼓,军鼓等)的WAV声音样本.因为我需要紧凑地播放声音,所以我需要高性能.目前,我正在使用:

  1. import sun.audio.*;
  2. import java.io.*;
  3. public class MusicPlayer {
  4. private String filename;
  5. public MusicPlayer(String filename) {
  6. this.filename = filename;
  7. }
  8. public void play() {
  9. try {
  10. InputStream in = new FileInputStream(filename);
  11. AudioStream as = new AudioStream(in);
  12. AudioPlayer.player.start(as);
  13. } catch (IOException e) {
  14. e.printStackTrace();
  15. }
  16. }
  17. }

如此处建议:How can I play sound in Java?

虽然它的工作速度比MP3 Javazoom jLayer快,但在高速和我进行cpu密集的工作(如调整应用程序窗口的大小)时,它仍然听起来不稳定.

有任何提高性能提示吗?

顺便说一句.我还阅读了不推荐使用sun.audio.*的信息.有没有类似的解决方案?

最佳答案
您是否看过Java Media Framework (JMF)

The 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.

猜你在找的Java相关文章