Created
October 4, 2009 14:16
-
-
Save angerman/201412 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 [javax.sound.sampled AudioSystem DataLine$Info SourceDataLine]) | |
(defn audio-copy [input output] ;; copy-n-past from duck-streams 'copy | |
(let [buffer (make-array Byte/TYPE *buffer-size*)] | |
(loop [] | |
(let [size (.read input buffer)] | |
(when (pos? size) | |
(do (.write output buffer 0 size) | |
(recur))))))) | |
(defn play [#^File t] | |
(let [stream (AudioSystem/getAudioInputStream t) | |
format (.getFormat stream) | |
info (DataLine$Info. SourceDataLine format) | |
line (AudioSystem/getLine info)] | |
(doto line | |
(.open format) | |
(.start)) | |
(audio-copy stream line) | |
(doto line | |
(.drain) | |
(.close)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment