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:

(ns sound-tests
  (:import
      (javax.sound.sampled AudioInputStream
                           AudioSystem
                           Clip
                           LineEvent
                           LineListener
                           LineUnavailableException
                           UnsupportedAudioFileException)
        (javax.sound.sampled.LineEvent.Type)
        (java.io IOException)
        (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)
                         (. javax.sound.sampled.LineEvent$Type
STOP)))
              (.close clip)
              (.close stream)))))
     (try
       (.open clip stream)
       (.start clip)
       (catch Exception e nil))))

(simple-play (URL. "file:///Users/verec/Tools/workspace/BetfairV6_new/
resources/com/mac/verec/betfair/sounds/tinkalink2.wav"))
--
JFB


On Jul 28, 2:00 am, Rayne <disciplera...@gmail.com> wrote:
> I've googled around, and found several ways to do this in Java, but
> I've not been successful in translating the less-complex examples. I'm
> wondering, how would an experienced Clojurian go about doing this in
> Clojure?
>
> All I'm trying to do is play a simple .wav sound file once.
>
> I'll appreciate any examples!
>
> -Anthony
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to