diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-18 17:32:13 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-18 17:32:13 -0500 |
| commit | 347e36c6fd4b52e14731594e6f745f6efdccadb1 (patch) | |
| tree | 47afd50f2be12aa5292b90989480a0a1f46f8001 /modules | |
| parent | c3720afd638270dc3fcc2b6ee4f7d26bdde634e8 (diff) | |
| download | dotemacs-347e36c6fd4b52e14731594e6f745f6efdccadb1.tar.gz dotemacs-347e36c6fd4b52e14731594e6f745f6efdccadb1.zip | |
refactor(media): extract the playback sentinel as a named builder
- cj/media--play-sentinel returns the per-process closure.
- Three new tests pin the reap-on-exit behavior.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/media-utils.el | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/modules/media-utils.el b/modules/media-utils.el index e3f4022f..99b5dc37 100644 --- a/modules/media-utils.el +++ b/modules/media-utils.el @@ -162,6 +162,19 @@ nothing." (error "yt-dlp resolved no stream URL for %s" url)))) (delete-file err-file)))) +(defun cj/media--play-sentinel (url-display) + "A process sentinel reporting playback of URL-DISPLAY. +Messages success or failure and reaps the process buffer once the +player finishes or exits." + (lambda (proc event) + (cond + ((string-match-p "finished" event) + (message "✓ Finished playing: %s" url-display)) + ((string-match-p "exited abnormally" event) + (message "✗ Playback failed: %s" url-display))) + (when (string-match-p "finished\\|exited" event) + (kill-buffer (process-buffer proc))))) + (defun cj/media-play-it (url) "Play the URL with the configured media player in an async process. A player flagged :needs-stream-url gets the URL resolved first via a @@ -193,16 +206,7 @@ with a plain argv list -- no shell anywhere in the pipeline." (cj/log-silently "DEBUG: Executing: %s" (string-join argv " ")) (let ((process (apply #'start-process player-name buffer-name argv))) - (set-process-sentinel - process - (lambda (proc event) - (cond - ((string-match-p "finished" event) - (message "✓ Finished playing: %s" url-display)) - ((string-match-p "exited abnormally" event) - (message "✗ Playback failed: %s" url-display))) - (when (string-match-p "finished\\|exited" event) - (kill-buffer (process-buffer proc))))))))) + (set-process-sentinel process (cj/media--play-sentinel url-display)))))) ;; ------------------------- Media-Download Via yt-dlp ------------------------- |
