Skip to content

Instantly share code, notes, and snippets.

@demoth
Last active November 24, 2023 18:10
Show Gist options
  • Save demoth/e6d7b75f63d3dbe86a2b136e365c4154 to your computer and use it in GitHub Desktop.
Save demoth/e6d7b75f63d3dbe86a2b136e365c4154 to your computer and use it in GitHub Desktop.
Simple audio WAV player based on javax sound clip api
import java.io.BufferedInputStream
import java.io.FileInputStream
import javax.sound.sampled.*
// expect a path to a wav file as a first argument
fun main(args: Array<String>) {
val fileInputStream = BufferedInputStream(FileInputStream(args.first()))
val audioInputStream = AudioSystem.getAudioInputStream(fileInputStream)
val clip = AudioSystem.getClip()
clip.open(audioInputStream)
clip.start()
// Keep the program running until the audio has finished playing.
while (!clip.isRunning())
Thread.sleep(10);
while (clip.isRunning())
Thread.sleep(10);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment