Windows 7 上的 Java 声音 API

标签 java audio windows-7

我在 http://www.tutorials.de/threads/java-einen-sound-abspielen.17178/ 找到了这个测试代码 它可以在 OSX 上运行,但不能在我的 PC Win7 上运行。 Win7 上的声音 API 有问题吗? 我安装了多个声音设备(集成的和 FireWire AudioInterface),并尝试了这两个设备,但什么也没听到。

import javax.sound.sampled.*;
import java.io.*;

/*
 * SoundTest.java
 *
 * Created on 1. August 2003, 21:06
 */

/**
 *
 * @author  Administrator
 */
public class SoundTest {

    /** Creates a new instance of SoundTest */
    public SoundTest() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        try{
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("sample.wav"));
            AudioFormat af     = audioInputStream.getFormat();
            int size      = (int) (af.getFrameSize() * audioInputStream.getFrameLength());
            byte[] audio       = new byte[size];
            DataLine.Info info      = new DataLine.Info(Clip.class, af, size);
            audioInputStream.read(audio, 0, size);

           // for(int i=0; i < 32; i++) {
                Clip clip = (Clip) AudioSystem.getLine(info);
                clip.open(af, audio, 0, size);
                clip.start();
           // }
        }catch(Exception e){ e.printStackTrace(); }

    }

}

感谢您的回复!

J

最佳答案

如果您使用的是 Java 7,我建议尝试 JavaFX API。它们更加先进并且跨平台兼容。在有人询问之前,使用 JavaFX 时您不仅限于网络。

关于Windows 7 上的 Java 声音 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24737315/

相关文章:

Perl Apache : Perl script displayed as plain text

java - 如何在 Windows 中获取具有 "tasklist"的进程的 CPU 使用率

java - ConcurrentHashMap 和 Hash 表的区别

java - 如果未找到结果,则显示 Toast

python - dejavu.py 识别的歌曲的附加信息

ruby-on-rails - 在 Windows 7 上安装 Ruby on Rails - 快速简单

java - JPA - EntityManager 的 findByProperty() 等效项

c# - 使用NAudio混合两个音频文件

audio - .og音频文件的WAV音频转换问题

oracle - TOAD for Oracle和Windows 7 : Can't initialize OCI.错误-1