mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Add currently playing bar
This commit is contained in:
parent
54757930d7
commit
19aa7038b3
4 changed files with 70 additions and 6 deletions
|
|
@ -3,11 +3,33 @@
|
|||
|
||||
;; TODO: Manage multiple songs, buffering, stopping, progress notification...
|
||||
|
||||
(def current-audio (atom nil))
|
||||
(defonce current-audio (atom nil))
|
||||
|
||||
(defn ->status
|
||||
"Takes an audio object and returns a map describing its current status"
|
||||
[elem]
|
||||
{:ended? (.-ended elem)
|
||||
:loop? (.-loop elem)
|
||||
:muted? (.-muted elem)
|
||||
:paused? (.-paused elem)
|
||||
:current-src (.-currentSrc elem)
|
||||
:current-time (.-currentTime elem)})
|
||||
|
||||
; explanation of these events: https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics
|
||||
(defn attach-listeners! [el]
|
||||
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
||||
(.addEventListener el event #(re-frame/dispatch [:audio-update (->status el)]))))
|
||||
|
||||
|
||||
(re-frame/reg-fx
|
||||
:play-song
|
||||
(fn [song-url]
|
||||
(let [audio (js/Audio. song-url)]
|
||||
(reset! current-audio audio)
|
||||
(attach-listeners! audio)
|
||||
(.play audio))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:pause-song
|
||||
(fn [_]
|
||||
(some-> @current-audio .pause)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue