feat: add media session API on now-playing update

This commit is contained in:
Luis Pereira 2026-02-20 17:26:14 +00:00 committed by Brian O'Reilly
parent 61266647a9
commit 8700724f81
5 changed files with 832 additions and 794 deletions

View File

@ -49,7 +49,8 @@
(:file "template-utils")
(:file "parenscript-utils")
(:module :parenscript
:components ((:file "recently-played")
:components ((:file "parenscript-utils")
(:file "recently-played")
(:file "auth-ui")
(:file "front-page")
(:file "profile")

View File

@ -222,9 +222,9 @@
(catch (lambda (error)
;; Silently fail
nil)))))
;; Update now playing info from API
(defun update-now-playing ()
(defun update-now-playing()
(let ((mount (get-current-mount)))
(ps:chain
(fetch (+ "/api/asteroid/partial/now-playing?mount=" mount))
@ -250,19 +250,25 @@
;; Check if this track is in user's favorites
(check-favorite-status)
;; Update favorite count display
(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-favorite-information)
(update-media-session new-title)))))))))
(catch (lambda (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
(defun update-stream-information ()
(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-favorites-cache)
(update-favorite-information)
;; Update now playing
(update-now-playing)
@ -864,4 +871,6 @@
(defun generate-front-page-js ()
"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

View File

@ -524,6 +524,7 @@
(setf (ps:@ el text-content) title)
;; Check if this track is in user's favorites
(check-favorite-status-mini))
(update-media-session title)
(when track-id-el
(let ((track-id (or (ps:@ data data track_id) (ps:@ data track_id))))
(setf (ps:@ track-id-el value) (or track-id ""))))
@ -634,7 +635,8 @@
(when title-el
(setf (ps:@ title-el text-content) (ps:chain track-text (trim))))
(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)
(ps:chain console (error "Error updating now playing:" error)))))))
@ -1082,4 +1084,6 @@
(defun generate-stream-player-js ()
"Generate JavaScript code for the stream player"
*stream-player-js*)
(ps-join
*common-player-js*
*stream-player-js*))

BIN
static/asteroid-squared.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB