Java:播放WAV声音

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

我正在尝试构建一个@L_301_0@鼓机,该鼓机需要播放各种鼓声部件(低音鼓,军鼓等)的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密集的工作(如调整应用程序窗口的大小)时,它仍然听起来不稳定.

有任何提高性能提示吗?

顺便说一句.我还阅读了不推荐使用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.

原文链接:https://www.f2er.com/java/533002.html

猜你在找的Java相关文章