Ok, here is some more code:

The line (-> in Player. .play) nil)) in the first function is what I'm 
trying to wrap in a future. The first two functions are basically what is 
used when trying to play a sound. The other 3 is the "main loop" part of my 
program. I don't think anything else is relevant.

(defn play-mp3 [name]
  (with-open [in (jio/input-stream (str audiodir name ".mp3"))]
    (-> in Player. .play) nil))

(defn play
  ([words-map] (play words-map "1"))
  ([words-map n] (let [mp3-n (min (Integer/parseInt n) (:mp3s @last-info))]
                   (if (and @last-word (pos? mp3-n))
                     (play-mp3 (str @last-word mp3-n))
                     {:output "play what?"}))))

(def cmds (let [cmds ["add" "delete" "random" "show" "help" "play"]
                cmds (zipmap cmds (map #(ns-resolve 'dictionary.core 
(symbol %)) cmds))]
            (conj cmds ["key" pron-key] ["lookup" lookup-cmd])))

(defn handle [cmd]
  (let [[cmd & args] (str/split cmd #"\s+")
        matching (starts-with-in cmd cmds)]
    (when (= 1 (count matching))
      (let [{:keys [output new-words-map]}
            (apply (val (first matching)) @words-atom args)]
        (if output (println output))
        (if new-words-map (reset! words-atom new-words-map))))
    (if (and (or (.startsWith "exit" cmd) (.startsWith "quit" cmd)) (pos? 
(count cmd)))
      false
      true)))


(defn -main [& args]
  (def words-atom (atom (load-words)))
  (loop []
    (print "> ") (flush)
    (let [cmd (read-line)]
      (println)
      (when (handle cmd)
        (println)
        (store-words @words-atom)
        (recur))))
  (shutdown-agents))

On Monday, December 31, 2012 12:12:09 AM UTC+1, Moritz Ulrich wrote:
>
> Laziness might be your problem, but that wouldn't explain (println 
> "called") working without a deref. 
>
> Can you show a bit more code around this call to `future'? 
>
> On Sun, Dec 30, 2012 at 8:31 AM, Oskar Kvist 
> <oskar...@gmail.com<javascript:>> 
> wrote: 
> > Hi! 
> > 
> > I'm trying to play a sound in my application, using 
> > http://www.javazoom.net/javalayer/documents.html that lib. Anyway, I 
> tried 
> > playing the sound in a future, so the main thread would not block while 
> > playing, like so: (future (-> in Player. .play)). But if I don't deref 
> the 
> > future, the sound does not play. If I do deref it, the sound plays, but 
> I 
> > have to wait for it, which is what I wanted to avoid. If I do (future 
> (do 
> > (println "called") (-> in Player. .play))), without a deref, it prints 
> > "called" but does still not play the sound. If I do (future (do (-> in 
> > Player. .play) (println "called"))), without a deref, it neither prints 
> nor 
> > plays. What could be wrong? 
> > 
> > I'm using clojure 1.4.0 and `lein trampoline run -m ns/main` to run my 
> > program. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@googlegroups.com<javascript:> 
> > Note that posts from new members are moderated - please be patient with 
> your 
> > first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
>

-- 
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