gpt4 book ai didi

java - 使用 Java Media Framework 在 Java 中播放 WAV 文件

转载 作者:行者123 更新时间:2023-12-01 04:18:40 24 4
gpt4 key购买 nike

The project in Eclipse

The Eclipse console output

为什么它不起作用?我什至尝试使用 isRuning 方法测试剪辑是否正在运行,我得到的唯一结果是文件长度和 False 作为对 isRunning 的返回强>方法。

我尝试播放的 WAV 文件来自 WikipediaWAV 文件文章,是格式表中的第二个文件。我想它的格式相当好。

最佳答案

由于我无法真正看到您的代码,因此我发布了我的操作方法,此代码“加载”了声音:

    AudioInputStream audioPush = null;

try {
push = AudioSystem.getClip();

URL urlPush = getClass().getResource(
"path to the file");

audioPush = AudioSystem.getAudioInputStream(urlPush);

push.open(audioPush);

} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

}

然后你必须像这样玩:

push.start();

我就是这样做的,不知道是否还有其他方法,但这个有效。

关于java - 使用 Java Media Framework 在 Java 中播放 WAV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19198368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com