aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2024-01-28 02:38:44 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2024-01-28 03:00:13 +0100
commit7063cb7bb3d5e199b69a82cbb2062a4386ee1556 (patch)
tree86aad9cc886ba8d53607d051c75673b314e142b1 /src
parent7ee8ab7375bb6ea96fae43c840ab464ffc71c5ac (diff)
fix(frontend): fix audio player pause
Diffstat (limited to 'src')
-rw-r--r--src/frontend/tubo/components/audio_player.cljs6
-rw-r--r--src/frontend/tubo/components/play_queue.cljs2
-rw-r--r--src/frontend/tubo/events.cljs19
3 files changed, 16 insertions, 11 deletions
diff --git a/src/frontend/tubo/components/audio_player.cljs b/src/frontend/tubo/components/audio_player.cljs
index 3e096e7..6c07fe2 100644
--- a/src/frontend/tubo/components/audio_player.cljs
+++ b/src/frontend/tubo/components/audio_player.cljs
@@ -31,7 +31,9 @@
:loop (= loop-playback :stream)
:on-loaded-data #(rf/dispatch [::events/player-start])
:muted muted?
- :on-time-update #(reset! !elapsed-time (.-currentTime @!player))}]))})))
+ :on-time-update #(reset! !elapsed-time (.-currentTime @!player))
+ :on-pause #(rf/dispatch [::events/change-player-paused true])
+ :on-play #(rf/dispatch [::events/change-player-paused false])}]))})))
(defn main-controls
[service-color]
@@ -59,7 +61,7 @@
(if paused?
[:i.fa-solid.fa-play]
[:i.fa-solid.fa-pause]))
- #(rf/dispatch [::events/player-paused (not paused?)])
+ #(rf/dispatch [::events/set-player-paused (not paused?)])
:show-on-mobile? true
:extra-styles "lg:text-2xl"]
[player/button [:i.fa-solid.fa-forward]
diff --git a/src/frontend/tubo/components/play_queue.cljs b/src/frontend/tubo/components/play_queue.cljs
index 133cc9b..a2b1190 100644
--- a/src/frontend/tubo/components/play_queue.cljs
+++ b/src/frontend/tubo/components/play_queue.cljs
@@ -89,7 +89,7 @@
(if paused?
[:i.fa-solid.fa-play]
[:i.fa-solid.fa-pause]))
- #(rf/dispatch [::events/player-paused (not paused?)])
+ #(rf/dispatch [::events/set-player-paused (not paused?)])
:extra-styles "text-3xl"
:show-on-mobile? true]
[player/button
diff --git a/src/frontend/tubo/events.cljs b/src/frontend/tubo/events.cljs
index 53bc059..0ee184d 100644
--- a/src/frontend/tubo/events.cljs
+++ b/src/frontend/tubo/events.cljs
@@ -30,7 +30,6 @@
:volume-level (if (nil? volume-level) 100 volume-level)
:bookmarks (if (nil? bookmarks) [] bookmarks)
:muted (if (nil? muted) false muted)
- :paused true
:current-match nil
:show-audio-player (if (nil? show-audio-player) false show-audio-player)
:settings
@@ -86,19 +85,24 @@
(fn [{:keys [time player]}]
(set! (.-currentTime @player) time)))
+(rf/reg-event-db
+ ::change-player-paused
+ (fn [db [_ val]]
+ (assoc db :paused val)))
+
(rf/reg-event-fx
- ::player-paused
+ ::set-player-paused
[(rf/inject-cofx ::inject/sub [:player])]
(fn [{:keys [db player]} [_ paused?]]
- {:db (assoc db :paused paused?)
- ::player-pause {:paused? (not paused?)
+ {::player-pause {:paused? (not paused?)
:player player}}))
(rf/reg-event-fx
::player-start
[(rf/inject-cofx ::inject/sub [:player]) (rf/inject-cofx ::inject/sub [:elapsed-time])]
(fn [{:keys [db player]} _]
- {:fx [[:dispatch [::player-paused false]]
+ {:fx [[:dispatch [::change-player-paused true]]
+ [:dispatch [::set-player-paused false]]
[::player-volume {:player player :volume (:volume-level db)}]]}))
(rf/reg-event-fx
@@ -346,7 +350,7 @@
(assoc :media-queue-pos 0)))]
{:db (remove-entries db)
:store (remove-entries store)
- :fx [[:dispatch [::player-paused true]]
+ :fx [[:dispatch [::set-player-paused true]]
[:dispatch [::set-player-time 0]]]})))
(rf/reg-event-fx
@@ -539,8 +543,7 @@
[(rf/inject-cofx ::inject/sub [:player])]
(fn [{:keys [db player]} [_ idx play? res]]
(let [stream-res (js->clj res :keywordize-keys true)]
- {:db (assoc db :show-audio-player-loading false
- :paused false)
+ {:db (assoc db :show-audio-player-loading false)
:fx (apply conj [[:dispatch [::change-media-queue-stream
(-> stream-res :audio-streams first :content)
idx]]]