From 7ed025ce3c80cc93f86d0a07cde15d487bcfb56c Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Tue, 4 Jun 2024 22:02:45 +0200 Subject: feat: show background player after loading stream --- src/frontend/tubo/player/events.cljs | 20 +++++++++++--------- src/frontend/tubo/queue/events.cljs | 4 +--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/frontend') 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? -- cgit v1.2.3