问题标签 [javax.sound.sampled]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 使用 clip.open 启动音乐时出现 Java 负数组大小异常
我目前正在尝试使用 将音乐启动到我的程序中javax.sound.sampled
,并且我编写了一个名为 music 的方法,该方法应该在执行时启动音乐剪辑。它是这样的:
当我尝试运行它时,我得到了一个未捕获的异常(程序没有启动),它说:
java - Any supported sound formats for Java on Windows 7?
We'll, I've been beating my head against a wall trying to get Java to play some simple wav files without any luck. I've tried this code:
This fails on "clip.open(...)" with the Exception:
And I've tried the more complicated (streaming version):
This also fails on "sourceLine.open(...)" with the Exception:
I've tried two different wav files, including the venerable "tada.wav" that comes in C:\Windows\Media.
I also used GoldWave to change one of the files to unsigned 8 bit mono, but that only changed the error message to:
Any thoughts on where I might be going wrong? Seems like playing a simple wave file should be simple, so I'm guessing I've gotten off in the weeds somewhere.
Thanks in advance.
UPDATE
So, the plot thickens. The code works fine if we move it into a separate stand alone java program. Something in our application must be cooking the Java's ability to play sounds.
Here is the stack trace for the above errors:
UPDATE 2
More interesting finds. It seems that we have a conflict when loading DLLs. We have our own DLL to help us do things (such as find a reliable and usable MAC Address). If you play a sound (which loads the sound related DLLs) before you load our DLL, then both work. However, if you our DLL and then try to play a sound, the sound gives you the errors reported above.
Anyone have any insight into why a seemingly unrelated DLL would cause another DLL to load incorrectly later?
As an entry for really lame and bad workarounds, we can play a fraction of a second of silence on start up before we look up the MAC address. This is bad form for several reasons including that many of our clients don't use sound at all.
UPDATE 3
Digging into our library, it seems the problem is caused by a call to RegisterClassEx(...). We do this so we can display an embedded IE window with our HTML help file.
java - 音频输入流不工作
每次用户按下按钮时,我都会尝试播放 .wav 声音,但会引发异常:
这是代码:
java - 写入 SourceDataLine 时无法执行任何操作
我对 Java 中的音频有点陌生。我正在尝试做的是在播放音频时,我想重新绘制我的JComponent
,但SourceDataLine
阻止所有其他代码行,包括其他线程。这是我的play()
方法
java - 不调用 TargetDataLine 的自定义实现方法
我试图开始使用 javax.sound.sampled-package。
我尝试实现我自己的 TargetDataLine 版本(此时出于测试目的)。然而,令我非常沮丧的是,当我完成并尝试“播放”它时,它的任何一个方法都没有被调用(也没有引发任何异常),而是程序冻结了。
有问题的代码段如下所示:
上面提到的代码永远不会到达“opened”语句,或者抛出异常。我尝试将打印输出插入到 AssembledDataLine 中实现的每个方法中,但它们都没有被调用(除了 writeArray,它在打开流之前被调用)。
所以在这一点上,我认为 Clip.open(stream) 方法甚至在达到从流中获取输入的点之前就冻结了。
我尝试以相同的方式打开文件并且它有效,所以我认为这与我实例化 AudioInputStream 的方式有关。
java - javax.sound.sampled.clip 在播放声音之前终止
我很困惑为什么这会立即终止……到目前为止,调试器并没有真正的帮助……我确信代码一直在运行。
nullpointerexception - 对 javax.sound.sampled.Clip NullPointerException 感到困惑
对在 Mac 上的 Eclipse 上运行的 javax.sound.sampled.Clip NullPointerException 感到困惑。输入波形文件存在,构造函数工作正常。对象实例被创建。只是无法访问实例方法,其中任何一个。这里可能是 Java 101 问题,所以我提前道歉,如果是这样?或者 Eclipses 101,就此而言......
/=====
}
java - 从java中的字节数组写入.wav文件
我需要读取一个.WAV
文件,应用某种半音偏移,然后将其重写为一个新.WAV
文件。
我想出了如何将文件转换为字节数组,但我不确定如何将其重写为新.WAV
文件。我正在使用javax.sound.sampled.*
图书馆。
我知道有一个函数AudioSystem.write(AudioInputStream, FileFormat, File)
,但我只是不知道如何AudioInputStream
从字节数组创建。有任何想法吗?
java - TargetDataLine 不会在插件项目中停止
我正在制作一个从麦克风录制并保存到音频 WAVE 文件的程序。代码成功执行,但我注意到在插件项目中完成记录后程序永远不会结束。
所以我尝试了这段代码(如下所示),但程序永远不会结束。为什么?我该如何解决这个问题?
谢谢!
java - 如何一次播放一个 .wav 文件?
我想创建一个在按下某个按钮时播放某个 .wav 文件的程序。例如分别JButton b1, b2, b3
播放"Music1.wav"
, "Music2.wav"
, 和"Music3.wav"
,但一次只能播放一个 wav 文件。这就是我所做的,它在停止较早的剪辑并导致两个或多个 wav 文件同时播放时存在问题。