2009/7/28 verec <[email protected]>:
>
> Here's a simple translation of my java production code (tested on OSX/
> Vista/XP, java 1.5 & 6)
> The gotcha is to forget the line listener and never dispose the
> resources.
> When I first tried without it, it worked perfectly on OS X but
> stacked sound threads upon sound threads on XP.
>
> This very same (java) code has been tested with: .wav. .aiff, .aif.
> and .au and works fine :-)
>
> So here's my clojure attempt:
That's a useful example :)
I removed some of the imports that aren't being used:
(ns sound-tests
(:import
(javax.sound.sampled AudioSystem LineEvent$Type LineListener)
(java.net URL)))
(defn simple-play
[url]
(let [stream (AudioSystem/getAudioInputStream url)
clip (AudioSystem/getClip)]
(.addLineListener clip
(proxy[LineListener] []
(update [event]
(when (and event
(= (.getType event)
(LineEvent$Type/STOP)))
(.close clip)
(.close stream)))))
(try
(.open clip stream)
(.start clip)
(catch Exception e nil))))
(simple-play (URL.
"file:///Developer/Examples/Java/Sound/JavaSoundDemo/audio/1-welcome.wav"))
--
Michael Wood <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---