            [:span {:className "album"}
             (get track "album")]]
           [:span {:className "buttons"}
-           [:button {:onClick (swallowing player-prev) }
+           [:button {:onClick
+                     (swallowing #(put! command-chan [:previous-track]))}
             (svg-skip-track :backwards)]
-           [:button {:onClick (swallowing player-pause) }
-            (if playing? (svg-pause) (svg-play))]
-           [:button {:onClick (swallowing player-next) }
+           [:button {:onClick
+                     (swallowing #(put! command-chan [:toggle-pause]))}
+            (case playing
+              true (svg-pause)
+              :pending (svg-spinner)
+              false (svg-play))]
+           [:button {:onClick
+                     (swallowing #(put! command-chan [:next-track]))}
             (svg-skip-track)]]
           [:span {:className "offset"}
            [:span {:className "elapsed-time time"}
-            (mmss (:track-offset (player-state)))]
+            (mmss (-> wanted :audio-el :time-offset))]
            " / "
            [:span {:className "track-time"}
             (mmss (get track "length" 0))]]

  (reify
    om/IRender
    (render [this]
      (let [queue (om/observe owner (player-queue))]
        (html
         [:div {}
          [:div {:className "track header"}
           [:span {:className "artist"} "Delete queue"]
           [:button {:onClick #(dequeue-all)} "-"]]
          (map #(om/build queue-track-view
                          %1
                          {:state
                           {:index %2
                            :current? (= (-> app :player :track-number)
                                         %2)
                            }})
               queue (range 0 999))
          ])))))

           (om/build queue-view state)]
          [:div {:className "queue tracks" } " "])
        (om/build transport-buttons-view state)
        (om/build audio-el (:audio-el (:player state)))
        ]))))

(defmulti dispatch-command (fn  [command & args] command))

(defmethod dispatch-command :enqueue [_ track]
  (swap! app-state #(update-in % [:player :queue] enqueue-track track)))

(defmethod dispatch-command :toggle-pause [_]
  (swap! app-state #(update-in % [:player :want-play] not)))

(defmethod dispatch-command :next-track [_]
  (swap! app-state #(update-in % [:player :queue] advance-queue)))

;; still to add: [dequeue previous-track delete-queue]

(defn command-loop []
  (let [ch (chan)]
    (go
      (loop []
        (let [command (<! ch)]
          (apply dispatch-command command)
          (recur))))
    ch))

(defn init []
  (add-watch app-state :transport sync-transport)
  (let [el (. js/document (getElementById "om-app"))
        command-chan (command-loop)
        search (chan)]
    (om/root app-view app-state
             {:target el
              :shared {:command-channel command-chan
                       :search-channel search}})))

(.addEventListener js/window "load" init)
(cljs.test/run-tests)
