diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/tubo/player/events.cljs | 20 | ||||
-rw-r--r-- | src/frontend/tubo/queue/events.cljs | 4 |
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? |