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 "parenscript-utils")
|
||||
(:module :parenscript
|
||||
:components ((:file "recently-played")
|
||||
:components ((:file "parenscript-utils")
|
||||
(:file "recently-played")
|
||||
(:file "auth-ui")
|
||||
(:file "front-page")
|
||||
(:file "profile")
|
||||
|
|
|
|||
|
|
@ -250,6 +250,13 @@
|
|||
;; Check if this track is in user's favorites
|
||||
(check-favorite-status)
|
||||
;; Update favorite count display
|
||||
(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)
|
||||
|
|
@ -259,9 +266,8 @@
|
|||
(if (= fav-count 1)
|
||||
"1 person loves this track ❤️"
|
||||
(+ fav-count " people love this track ❤️")))
|
||||
(setf (ps:@ count-el text-content) "")))))))))))))
|
||||
(catch (lambda (error)
|
||||
(ps:chain console (log "Could not fetch stream status:" error)))))))
|
||||
(setf (ps:@ count-el text-content) ""))))))
|
||||
|
||||
|
||||
;; Update stream information
|
||||
(defun update-stream-information ()
|
||||
|
|
@ -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*))
|
||||
|
|
|
|||
|
|
@ -3,9 +3,30 @@
|
|||
|
||||
(in-package #:asteroid)
|
||||
|
||||
(defparameter *player-js*
|
||||
(defparameter *common-player-js*
|
||||
(ps:ps*
|
||||
'(progn
|
||||
(defun update-media-session (title)
|
||||
(let ((media-session (ps:@ navigator media-session)))
|
||||
(when media-session
|
||||
(let ((track-title "Unknown")
|
||||
(now-playing-title-el (ps:chain document (query-selector "#current-track-title"))))
|
||||
(when title
|
||||
(setf track-title title))
|
||||
(when (and now-playing-title-el (not title))
|
||||
(let ((now-playing-title (ps:@ now-playing-title-el text-content)))
|
||||
(when now-playing-title
|
||||
(setf track-title now-playing-title))))
|
||||
(let* ((media-info (ps:create :title track-title
|
||||
:artwork (list (ps:create :src "/asteroid/static/asteroid-squared.png"
|
||||
:type "image/png"
|
||||
:sizes "256x256"))))
|
||||
(metadata (ps:new (-media-metadata media-info))))
|
||||
(setf (ps:@ media-session metadata) metadata)))))))))
|
||||
|
||||
(defparameter *player-js*
|
||||
(ps:ps*
|
||||
`(progn
|
||||
|
||||
;; Global variables
|
||||
(defvar *tracks* (array))
|
||||
|
|
@ -781,7 +802,8 @@
|
|||
(ps:chain console (log "Error connecting to stream"))
|
||||
"")))))
|
||||
(then (lambda (data)
|
||||
(setf (ps:chain document (get-element-by-id "now-playing") inner-h-t-m-l) data)))
|
||||
(setf (ps:chain document (get-element-by-id "now-playing") inner-h-t-m-l) data)
|
||||
(update-media-session)))
|
||||
|
||||
(catch (lambda (error)
|
||||
(ps:chain console (log "Could not fetch stream status:" error))))))
|
||||
|
|
@ -810,4 +832,6 @@
|
|||
|
||||
(defun generate-player-js ()
|
||||
"Generate JavaScript code for the web player"
|
||||
*player-js*)
|
||||
(ps-join
|
||||
*common-player-js*
|
||||
*player-js*))
|
||||
|
|
|
|||
|
|
@ -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*))
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue