is it possible to play sythesized (or, any actuall...
# compose-desktop
m
is it possible to play sythesized (or, any actually) sounds in Compose Desktop? I was trying to play around with both the
javax.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?
k
Can you do it from a Swing's
JFrame
from a
JButton
action listener on the same machine?
y
I don't know about any synthesized audio, but I use this in my compose app: I load the clip this way (in the main)
Copy code
var 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):
Copy code
clip?.framePosition = 0
        clip?.start()
m
@Kirill Grouchnikov I will look into this an report back. For JSyn, I was just attempting to play sound right on startup as a sanity check, basically mimicing this example, where I tried to start up & play right at the top of the invocation to
application { ...
, 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 check
p
@Yan Pujante where is your sounds folder? is this working in release mode?