Matthew Laser
02/22/2022, 1:35 AMjavax.sound.midi
package, as well as the JSyn package. I was able to get the same code playing sounds from a swing JApplet
, but haven't been able to hear anything coming out of Compose. Anyone have any ideas?Kirill Grouchnikov
02/22/2022, 2:19 AMJFrame
from a JButton
action listener on the same machine?Yan Pujante
02/22/2022, 2:21 PMvar clip = AudioSystem.getClip()
try {
val classLoader = Thread.currentThread().contextClassLoader
classLoader.getResourceAsStream("sounds/Ping.wav").use { stream ->
// implementation note: AudioSystem.getAudioInputStream needs a mark/reset stream
// which doesn't work in the case of a jar/zip input stream => need to copy first
val byteStream = ByteArrayInputStream(stream.readBytes())
clip.open(AudioSystem.getAudioInputStream(byteStream))
}
} catch (th: Throwable) {
// shouldn't happen
clip = null
th.printStackTrace()
}
I play it this way (on button press or whatever):
clip?.framePosition = 0
clip?.start()
Matthew Laser
02/22/2022, 4:39 PMapplication { ...
, as well as on button press, with no results.
@Yan Pujante thank you for sharing your code, I will look into this on my system as a sanity checkPablo
01/27/2025, 11:03 PM