feat: add media session API on now-playing update
This commit is contained in:
parent
61266647a9
commit
8700724f81
|
|
@ -49,7 +49,8 @@
|
||||||
(:file "template-utils")
|
(:file "template-utils")
|
||||||
(:file "parenscript-utils")
|
(:file "parenscript-utils")
|
||||||
(:module :parenscript
|
(:module :parenscript
|
||||||
:components ((:file "recently-played")
|
:components ((:file "parenscript-utils")
|
||||||
|
(:file "recently-played")
|
||||||
(:file "auth-ui")
|
(:file "auth-ui")
|
||||||
(:file "front-page")
|
(:file "front-page")
|
||||||
(:file "profile")
|
(:file "profile")
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@
|
||||||
nil)))))
|
nil)))))
|
||||||
|
|
||||||
;; Update now playing info from API
|
;; Update now playing info from API
|
||||||
(defun update-now-playing ()
|
(defun update-now-playing()
|
||||||
(let ((mount (get-current-mount)))
|
(let ((mount (get-current-mount)))
|
||||||
(ps:chain
|
(ps:chain
|
||||||
(fetch (+ "/api/asteroid/partial/now-playing?mount=" mount))
|
(fetch (+ "/api/asteroid/partial/now-playing?mount=" mount))
|
||||||
|
|
@ -250,19 +250,25 @@
|
||||||
;; Check if this track is in user's favorites
|
;; Check if this track is in user's favorites
|
||||||
(check-favorite-status)
|
(check-favorite-status)
|
||||||
;; Update favorite count display
|
;; Update favorite count display
|
||||||
(let ((count-el (ps:chain document (get-element-by-id "favorite-count-display")))
|
(update-favorite-information)
|
||||||
(count-val-el (ps:chain document (get-element-by-id "favorite-count-value"))))
|
(update-media-session new-title)))))))))
|
||||||
(when (and count-el count-val-el)
|
|
||||||
(let ((fav-count (parse-int (or (ps:@ count-val-el value) "0") 10)))
|
|
||||||
(if (> fav-count 0)
|
|
||||||
(setf (ps:@ count-el text-content)
|
|
||||||
(if (= fav-count 1)
|
|
||||||
"1 person loves this track ❤️"
|
|
||||||
(+ fav-count " people love this track ❤️")))
|
|
||||||
(setf (ps:@ count-el text-content) "")))))))))))))
|
|
||||||
(catch (lambda (error)
|
(catch (lambda (error)
|
||||||
(ps:chain console (log "Could not fetch stream status:" error)))))))
|
(ps:chain console (log "Could not fetch stream status:" error)))))))
|
||||||
|
|
||||||
|
;; Update favorite count display
|
||||||
|
(defun update-favorite-information ()
|
||||||
|
(let ((count-el (ps:chain document (get-element-by-id "favorite-count-display")))
|
||||||
|
(count-val-el (ps:chain document (get-element-by-id "favorite-count-value"))))
|
||||||
|
(when (and count-el count-val-el)
|
||||||
|
(let ((fav-count (parse-int (or (ps:@ count-val-el value) "0") 10)))
|
||||||
|
(if (> fav-count 0)
|
||||||
|
(setf (ps:@ count-el text-content)
|
||||||
|
(if (= fav-count 1)
|
||||||
|
"1 person loves this track ❤️"
|
||||||
|
(+ fav-count " people love this track ❤️")))
|
||||||
|
(setf (ps:@ count-el text-content) ""))))))
|
||||||
|
|
||||||
|
|
||||||
;; Update stream information
|
;; Update stream information
|
||||||
(defun update-stream-information ()
|
(defun update-stream-information ()
|
||||||
(let* ((channel-selector (or (ps:chain document (get-element-by-id "stream-channel"))
|
(let* ((channel-selector (or (ps:chain document (get-element-by-id "stream-channel"))
|
||||||
|
|
@ -635,6 +641,7 @@
|
||||||
|
|
||||||
;; Load user's favorites for highlight feature
|
;; Load user's favorites for highlight feature
|
||||||
(load-favorites-cache)
|
(load-favorites-cache)
|
||||||
|
(update-favorite-information)
|
||||||
|
|
||||||
;; Update now playing
|
;; Update now playing
|
||||||
(update-now-playing)
|
(update-now-playing)
|
||||||
|
|
@ -864,4 +871,6 @@
|
||||||
|
|
||||||
(defun generate-front-page-js ()
|
(defun generate-front-page-js ()
|
||||||
"Return the pre-compiled JavaScript for front page"
|
"Return the pre-compiled JavaScript for front page"
|
||||||
*front-page-js*)
|
(ps-join
|
||||||
|
*common-player-js*
|
||||||
|
*front-page-js*))
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -524,6 +524,7 @@
|
||||||
(setf (ps:@ el text-content) title)
|
(setf (ps:@ el text-content) title)
|
||||||
;; Check if this track is in user's favorites
|
;; Check if this track is in user's favorites
|
||||||
(check-favorite-status-mini))
|
(check-favorite-status-mini))
|
||||||
|
(update-media-session title)
|
||||||
(when track-id-el
|
(when track-id-el
|
||||||
(let ((track-id (or (ps:@ data data track_id) (ps:@ data track_id))))
|
(let ((track-id (or (ps:@ data data track_id) (ps:@ data track_id))))
|
||||||
(setf (ps:@ track-id-el value) (or track-id ""))))
|
(setf (ps:@ track-id-el value) (or track-id ""))))
|
||||||
|
|
@ -634,7 +635,8 @@
|
||||||
(when title-el
|
(when title-el
|
||||||
(setf (ps:@ title-el text-content) (ps:chain track-text (trim))))
|
(setf (ps:@ title-el text-content) (ps:chain track-text (trim))))
|
||||||
(when artist-el
|
(when artist-el
|
||||||
(setf (ps:@ artist-el text-content) "Asteroid Radio"))))))))
|
(setf (ps:@ artist-el text-content) "Asteroid Radio")))))
|
||||||
|
(update-media-session track-text))))
|
||||||
(catch (lambda (error)
|
(catch (lambda (error)
|
||||||
(ps:chain console (error "Error updating now playing:" error)))))))
|
(ps:chain console (error "Error updating now playing:" error)))))))
|
||||||
|
|
||||||
|
|
@ -1082,4 +1084,6 @@
|
||||||
|
|
||||||
(defun generate-stream-player-js ()
|
(defun generate-stream-player-js ()
|
||||||
"Generate JavaScript code for the stream player"
|
"Generate JavaScript code for the stream player"
|
||||||
*stream-player-js*)
|
(ps-join
|
||||||
|
*common-player-js*
|
||||||
|
*stream-player-js*))
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue