mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 10:43:39 +02:00
Add current playlist, next and previous
Also reuse audio element so slippery stuff like volume persists
This commit is contained in:
parent
4b00c21a74
commit
d24300ad1e
4 changed files with 59 additions and 31 deletions
|
|
@ -1,9 +1,9 @@
|
|||
(ns airsonic-ui.audio
|
||||
(:require [re-frame.core :as re-frame]))
|
||||
|
||||
;; TODO: Manage multiple songs, buffering, stopping, progress notification...
|
||||
;; TODO: Manage buffering
|
||||
|
||||
(defonce current-audio (atom nil))
|
||||
(defonce audio (atom nil))
|
||||
|
||||
(defn ->status
|
||||
"Takes an audio object and returns a map describing its current status"
|
||||
|
|
@ -23,16 +23,17 @@
|
|||
(re-frame/reg-fx
|
||||
:play-song
|
||||
(fn [song-url]
|
||||
(some-> @current-audio .pause)
|
||||
(let [audio (js/Audio. song-url)]
|
||||
(reset! current-audio audio)
|
||||
(attach-listeners! audio)
|
||||
(.play audio))))
|
||||
(when-not @audio
|
||||
(reset! audio (js/Audio.))
|
||||
(attach-listeners! @audio))
|
||||
(.pause @audio)
|
||||
(set! (.-src @audio) song-url)
|
||||
(.play @audio)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:toggle-play-pause
|
||||
(fn [_]
|
||||
(when-let [a @current-audio]
|
||||
(let [a @audio]
|
||||
(if (.-paused a)
|
||||
(.play a)
|
||||
(.pause a)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue