mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Pause current track when starting next, implement play / pause
This commit is contained in:
parent
491c172ae7
commit
4639f4ef27
3 changed files with 9 additions and 7 deletions
|
|
@ -20,16 +20,19 @@
|
||||||
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
||||||
(.addEventListener el event #(re-frame/dispatch [:audio-update (->status el)]))))
|
(.addEventListener el event #(re-frame/dispatch [:audio-update (->status el)]))))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:play-song
|
:play-song
|
||||||
(fn [song-url]
|
(fn [song-url]
|
||||||
|
(some-> @current-audio .pause)
|
||||||
(let [audio (js/Audio. song-url)]
|
(let [audio (js/Audio. song-url)]
|
||||||
(reset! current-audio audio)
|
(reset! current-audio audio)
|
||||||
(attach-listeners! audio)
|
(attach-listeners! audio)
|
||||||
(.play audio))))
|
(.play audio))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:pause-song
|
:toggle-play-pause
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(some-> @current-audio .pause)))
|
(when-let [a @current-audio]
|
||||||
|
(if (.-paused a)
|
||||||
|
(.play a)
|
||||||
|
(.pause a)))))
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,10 @@
|
||||||
:db (assoc-in db [:currently-playing :item] song)})))
|
:db (assoc-in db [:currently-playing :item] song)})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::pause-song
|
::toggle-play-pause
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
; pauses the current song
|
; pauses the current song
|
||||||
{:pause-song nil}))
|
{:toggle-play-pause nil}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
:audio-update
|
:audio-update
|
||||||
|
|
@ -91,7 +91,6 @@
|
||||||
(fn [{:keys [db]} [_ route params query]]
|
(fn [{:keys [db]} [_ route params query]]
|
||||||
;; all the naviagation logic is in routes.cljs; all we need to do here
|
;; all the naviagation logic is in routes.cljs; all we need to do here
|
||||||
;; is say what actually happens once we've navigated succesfully
|
;; is say what actually happens once we've navigated succesfully
|
||||||
(println "routes/route-data" (routes/route-data route params query))
|
|
||||||
{:db (assoc db :current-route [route params query])
|
{:db (assoc db :current-route [route params query])
|
||||||
:dispatch (routes/route-data route params query)}))
|
:dispatch (routes/route-data route params query)}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
(defn playback-controls []
|
(defn playback-controls []
|
||||||
[:div
|
[:div
|
||||||
[:button "previous"]
|
[:button "previous"]
|
||||||
[:button "play / pause"]
|
[:button {:on-click #(re-frame/dispatch [::events/toggle-play-pause])} "play / pause"]
|
||||||
[:button "next"]
|
[:button "next"]
|
||||||
[:label [:input {:type "checkbox"}] "shuffle"]
|
[:label [:input {:type "checkbox"}] "shuffle"]
|
||||||
[:label [:input {:type "checkbox"}] "repeat"]])
|
[:label [:input {:type "checkbox"}] "repeat"]])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue