aboutsummaryrefslogtreecommitdiff
path: root/src/frontend
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2024-06-04 22:02:45 +0200
committerMiguel Ángel Moreno <mail@migalmoreno.com>2024-06-04 22:02:45 +0200
commit7ed025ce3c80cc93f86d0a07cde15d487bcfb56c (patch)
tree2780a7320587d8e5998bc2e1468fc37ab894f7a6 /src/frontend
parentd96fa24251fd78e11a4c55db52e6e7b6a448b3cb (diff)
feat: show background player after loading stream
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/tubo/player/events.cljs20
-rw-r--r--src/frontend/tubo/queue/events.cljs4
2 files changed, 12 insertions, 12 deletions
diff --git a/src/frontend/tubo/player/events.cljs b/src/frontend/tubo/player/events.cljs
index 7ee2088..a0f4e3b 100644
--- a/src/frontend/tubo/player/events.cljs
+++ b/src/frontend/tubo/player/events.cljs
@@ -124,7 +124,7 @@
:media-session-handlers
(fn [{:keys [current-pos player stream]}]
(when (gobj/containsKey js/navigator "mediaSession")
- (let [current-time (.-currentTime @player)
+ (let [current-time (and @player (.-currentTime @player))
update-position
#(.setPositionState js/navigator.mediaSession
{:duration (.-duration @player)
@@ -204,10 +204,8 @@
(fn [{:keys [db store]} [_ stream notify?]]
(let [updated-db (update db :queue conj stream)
idx (.indexOf (:queue updated-db) stream)]
- {:db (assoc updated-db :background-player/show (not (:main-player/show db)))
- :store (-> store
- (assoc :background-player/show (not (:main-player/show db)))
- (assoc :queue (:queue updated-db)))
+ {:db updated-db
+ :store (assoc store :queue (:queue updated-db))
:fx [[:dispatch [:player/fetch-stream
(:url stream) idx (= (count (:queue db)) 0)]]
(when (and notify? (not (= (count (:queue db)) 0)))
@@ -248,10 +246,14 @@
(rf/reg-event-fx
:player/load-stream
- [(rf/inject-cofx ::inject/sub [:player])]
- (fn [{:keys [db player]} [_ idx play? res]]
+ [(rf/inject-cofx :store)
+ (rf/inject-cofx ::inject/sub [:player])]
+ (fn [{:keys [db store player]} [_ idx play? res]]
(let [stream-res (js->clj res :keywordize-keys true)]
- {:db (assoc db :background-player/loading false)
+ {:db (assoc db
+ :background-player/show (not (:main-player-show db))
+ :background-player/loading false)
+ :store (assoc store :background-player/show (not (:main-player-show db)))
:fx (apply conj [(when play? [:dispatch [:queue/change-stream stream-res idx]])]
(when (and (:background-player/ready db) play?)
[[:media-session-metadata
@@ -259,7 +261,7 @@
:artist (:uploader-name stream-res)
:artwork [{:src (:thumbnail-url stream-res)}]}]
[:media-session-handlers
- {:current-pos (:queue-pos db)
+ {:current-pos idx
:player player}]]))})))
(rf/reg-event-fx
diff --git a/src/frontend/tubo/queue/events.cljs b/src/frontend/tubo/queue/events.cljs
index b706452..0154cef 100644
--- a/src/frontend/tubo/queue/events.cljs
+++ b/src/frontend/tubo/queue/events.cljs
@@ -25,9 +25,7 @@
:queue/add-n
[(rf/inject-cofx :store)]
(fn [{:keys [db store]} [_ streams notify?]]
- {:db (assoc db :background-player/show (not (:main-player/show db)))
- :store (assoc store :background-player/show (not (:main-player/show db)))
- :fx (into (map (fn [stream] [:dispatch [:queue/add stream]]) streams)
+ {:fx (into (map (fn [stream] [:dispatch [:queue/add stream]]) streams)
[[:dispatch [:player/fetch-stream (-> streams first :url)
(count (:queue db)) (= (count (:queue db)) 0)]]
(when notify?