Created
December 16, 2012 17:05
-
-
Save olenhad/4309581 to your computer and use it in GitHub Desktop.
Simple wav player using java sound
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
(ns sound.core | |
(:import (java.io File) | |
(javax.sound.sampled AudioFormat AudioInputStream AudioSystem DataLine DataLine$Info LineUnavailableException SourceDataLine))) | |
(defn play-sound [filename] | |
(let | |
[ | |
sfile (new File filename) | |
ainput (AudioSystem/getAudioInputStream sfile) | |
aformat (.getFormat ainput) | |
info (DataLine$Info. SourceDataLine aformat) | |
line (AudioSystem/getLine info) | |
data (byte-array 128000) | |
] | |
(do | |
(.open line aformat) | |
(.start line) | |
(while (not= -1 (.read ainput data 0 128000)) | |
(.write line data 0 128000)) | |
(.drain line) | |
(.close line) | |
))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment