adjustment to the new audio-player module of racket-audio

This commit is contained in:
2026-05-19 15:01:32 +02:00
parent e60ecaeaef
commit 2f04cf2ff4
4 changed files with 59 additions and 20 deletions
+35 -16
View File
@@ -147,11 +147,21 @@
(unless (eq? stored-file #f) (unless (eq? stored-file #f)
(dbg-rktplayer "Setting album art") (dbg-rktplayer "Setting album art")
(let ((el (send this element 'album-art))) (let ((el (send this element 'album-art)))
(let ((html (format "<img src=\"/get-image?~a&~a\" />" (let ((html (format "<img id=\"album-image\" src=\"/get-image?~a&~a\" />"
(format "~a" stored-file) (format "~a" stored-file)
(current-milliseconds)))) (current-milliseconds))))
(dbg-rktplayer "Html = ~a" html) (dbg-rktplayer "Html = ~a" html)
(send el set-innerHTML! html) (send el set-innerHTML! html)
(when (send track has-booklet?)
(let ((booklet-file (send track booklet-file)))
(send this bind! 'album-image 'contextmenu
(λ (el evt data)
(let ((mnu (wv-menu 'image-menu
(wv-menu-item 'm-booklet (tr "Open booklet")
#:callback (λ () (send this open-booklet booklet-file #t)))))
(clientX (hash-ref data 'clientX 60))
(clientY (hash-ref data 'clientY 60)))
(send this popup-menu! mnu clientX clientY))))))
))) )))
) )
) )
@@ -173,26 +183,26 @@
) )
(define (update-state st) (define (update-state st)
(dbg-rktplayer "state: ~a" st)
(unless (eq? st state) (unless (eq? st state)
(dbg-rktplayer "Changing to state ~a" st) (dbg-rktplayer "Changing to state ~a" st)
(let ((el (send this element 'paused))) (let ((el (send this element 'paused)))
(unless (eq? state #f) ; Prevent setting src twice very fast (cond ((or (eq? st 'playing) (eq? st 'play))
(cond ((or (eq? st 'playing) (eq? st 'play)) (set-play-button "buttons/pause.svg")
(set-play-button "buttons/pause.svg") (send el set-innerHTML! '(span (tr "playing"))))
(send el set-innerHTML! '(span (tr "playing"))))
((eq? st 'stopped) ((eq? st 'stopped)
(set-play-button "buttons/play.svg") (set-play-button "buttons/play.svg")
(send el set-innerHTML! '(span (tr "stopped")))) (send el set-innerHTML! '(span (tr "stopped"))))
((eq? st 'paused) ((eq? st 'paused)
(set-play-button "buttons/play.svg") (set-play-button "buttons/play.svg")
(send el set-innerHTML! '(span ((class "blink")) (tr "paused")))) (send el set-innerHTML! '(span ((class "blink")) (tr "paused"))))
((eq? st 'quit)
(void))
(else (else
(warn-rktplayer "Unkown state for update-state ~a" st) (warn-rktplayer "Unkown state for update-state ~a" st)
(send el set-innerHTML! (list 'span (send el set-innerHTML! (list 'span
'((class "blink")) '((class "blink"))
(format "~a: ~a" (tr "Unknown state") st)))) (format "~a: ~a" (tr "Unknown state") st))))
))) ))
(set! state st) (set! state st)
) )
) )
@@ -309,10 +319,13 @@
(send this update-tabs)) (send this update-tabs))
(define (update-audio-info rate channels bits audio-format) (define (update-audio-info rate channels bits audio-format)
(send el-bits set-innerHTML! (format "~a ~a" bits (tr "bits"))) (let ((format-num (λ (x) (if (= x 0) "-" x)))
(send el-channels set-innerHTML! (format "~a ~a" channels (tr "channels"))) (format-dec (λ (x) (if (eq? x 'none) "-" x))))
(send el-rate set-innerHTML! (format "~a Hz" rate)) (send el-bits set-innerHTML! (format "~a ~a" (format-num bits) (tr "bits")))
(send el-format set-innerHTML! (format "~a" audio-format)) (send el-channels set-innerHTML! (format "~a ~a" (format-num channels) (tr "channels")))
(send el-rate set-innerHTML! (format "~a Hz" (format-num rate)))
(send el-format set-innerHTML! (format "~a" (format-dec audio-format)))
)
) )
(define (update-repeat state) (define (update-repeat state)
@@ -396,6 +409,10 @@
(send this update-tabs) (send this update-tabs)
(send this update-library) (send this update-library)
(send this update-playlist) (send this update-playlist)
(when (eq? state #f)
(update-audio-info 0 0 0 'none)
(update-state 'stopped))
) )
(define el-dragged #f) (define el-dragged #f)
@@ -564,9 +581,10 @@
(send this update-playlist) (send this update-playlist)
) )
(define/public (open-booklet path) (define/public (open-booklet path . is-file*)
(let ((booklet (build-path path "booklet.pdf"))) (let* ((is-file (if (null? is-file*) #f (eq? (car is-file*) #t)))
(dbg-rktplayer "Open booklet ~a" path) (booklet (if is-file path (build-path path "booklet.pdf"))))
(dbg-rktplayer "Open booklet ~a" booklet)
(open-app booklet))) (open-app booklet)))
(define/public (open-folder path) (define/public (open-folder path)
@@ -698,6 +716,7 @@
(set! playlist (new playlist% [settings (send settings clone 'playlists)])) (set! playlist (new playlist% [settings (send settings clone 'playlists)]))
(send player set-list! playlist) (send player set-list! playlist)
(dbg-rktplayer "playlist = ~a" playlist) (dbg-rktplayer "playlist = ~a" playlist)
(semaphore-post initialized) (semaphore-post initialized)
) )
) )
+9 -4
View File
@@ -44,7 +44,7 @@
(lru-clear track-cache)) (lru-clear track-cache))
(define (audio-state-cb handle st*) (define (audio-state-cb handle player-state st*)
(set! full-state st*) (set! full-state st*)
(let ((st (audio-state player))) (let ((st (audio-state player)))
(when (or (eq? st 'paused) (eq? st 'playing)) (when (or (eq? st 'paused) (eq? st 'playing))
@@ -59,8 +59,10 @@
) )
(state-updater st) (state-updater st)
(repeat-updater repeat) (repeat-updater repeat)
(audio-info-cb (audio-rate player) (audio-channels player) (if (or (eq? player-state 'quit) (eq? player-state 'stopped))
(audio-bits player) (audio-decoder player)) (audio-info-cb 0 0 0 'none)
(audio-info-cb (audio-rate player) (audio-channels player)
(audio-bits player) (audio-decoder player)))
) )
) )
@@ -70,7 +72,10 @@
(define (check-player) (define (check-player)
(when (eq? player #f) (when (eq? player #f)
(set! player (make-audio-player audio-state-cb on-eof-stream-cb)))) (set! player (make-audio-player audio-state-cb on-eof-stream-cb))
(audio-ao-buf-ms! player 500)
(audio-buf-seconds! player buffer-min-seconds buffer-max-seconds)
))
(define/public (get-volume) (define/public (get-volume)
(check-player) (check-player)
+8
View File
@@ -51,6 +51,14 @@
(define/public (get-length) length) (define/public (get-length) length)
(define/public (get-id) my-id) (define/public (get-id) my-id)
(define/public (booklet-file)
(let* ((dir (path-only file))
(booklet-file (build-path dir "booklet.pdf")))
booklet-file))
(define/public (has-booklet?)
(file-exists? (send this booklet-file)))
(define/public (track< t2) (define/public (track< t2)
(if (string-ci<? album (send t2 get-album)) (if (string-ci<? album (send t2 get-album))
#t #t
+7
View File
@@ -44,6 +44,11 @@
(send rktplayer-window close) (send rktplayer-window close)
(exit) (exit)
) )
(define-syntax ignore
(syntax-rules ()
((_ body)
#t)))
(define (run . no-exit) (define (run . no-exit)
@@ -59,6 +64,7 @@
) )
(set! rktplayer-window window) (set! rktplayer-window window)
(set! rktplayer-tray tray) (set! rktplayer-tray tray)
(ignore
(thread (λ () (thread (λ ()
(sleep 5) (sleep 5)
(let ((prg (string-append "let f_evt_info = window.rkt_event_info;\n" (let ((prg (string-append "let f_evt_info = window.rkt_event_info;\n"
@@ -91,6 +97,7 @@
(return 42)))))|# (return 42)))))|#
(displayln prg) (displayln prg)
(displayln (send window call-js prg))))) (displayln (send window call-js prg)))))
)
(when (or (null? no-exit) (when (or (null? no-exit)
(not (eq? (car no-exit) #t))) (not (eq? (car no-exit) #t)))
(webview-wait-for-quit) (webview-wait-for-quit)