Last active
November 24, 2023 18:10
-
-
Save demoth/e6d7b75f63d3dbe86a2b136e365c4154 to your computer and use it in GitHub Desktop.
Simple audio WAV player based on javax sound clip api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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