 
 (defn tab-on-view []
   (om/ref-cursor (:tab-on-view (om/root-cursor app-state))))
+
+(defn player-state []
+  (om/ref-cursor (:player (om/root-cursor app-state))))
+
+(defn player-pause []
+  (om/transact! (player-state) #(update-in % [:playing] not)))
+
+(defn player-next []
+  ;; how do we make this fail if there are no more tracks?
+  (om/transact! (player-state) #(update-in % [:track-number] inc)))
+
+(defn player-prev []
+  (let [dec0 #(max (dec %) 0)]
+    (om/transact! (player-state) #(update-in % [:track-number] dec0))))
+
+
+(defn player-el []
+  (aget (.getElementsByTagName js/document "audio") 0))
 
 (defn enqueue-track [track]
   (om/transact! (player-queue) #(conj % track)))

      (let [el (om/get-node owner)]
        ;; last arg "true" is cos audio events don't bubble
        ;; http://stackoverflow.com/questions/11291651/why-dont-audio-and-video-events-bubble
        (.addEventListener el "ended" #(dequeue-track 0) true)))
    om/IRender
    (render [this]
      (let [queue (om/observe owner (player-queue))
            on-view (om/observe owner (tab-on-view))
            bits (best-media-url (first queue))]
        (dom/audio #js {:controls "controls"
                        :autoPlay "true"
                        :ref "player"
                        :src bits})))))


(defn update-term [[command new-terms] previous]

              :playing true
              :track-offset 0
              :track-offset-when 0
              }
     }))

