Yoni Rabkin <[email protected]> writes:
Yuchen Pei <[email protected]> writes:Yoni Rabkin <[email protected]> writes:Mike Kazantsev <[email protected]> writes:On Wed, 20 Oct 2021 08:35:07 -0400 Yoni Rabkin <[email protected]> wrote:Maybe emms can just always store/update emms-playing-time on thetrack in playlist?That'd also double as "last stopped time" without adding any reallynewconcepts, and there's 'info-playing-time for total duration therealready. Otherwise implementation like this jumps to mind: (funcall (emms-player-get emms-player-playing-p 'query-position))It's what mpv currently does in response to events, and presumably backends that only get it from somewhere periodically (e.g. stdoutstatus line) can just cache it in some value.But if this is not implemented for backend, I'd think that fallbacktoemms-playing-time would seem reasonable, and then why not justalways store that in the first place? :)There is no reason not to do that; it wouldn't impact anything.Great. Now the question is who is going to submit a patch for this?I can do it if you want.Patches are always welcome here; we have an "open-door" policy towelcome sojourning code.
Please find attached a patch to add this facility and let me know what you think.
From fd37f9c452d615e42c2768a3a81a6700335f66d5 Mon Sep 17 00:00:00 2001 From: Yuchen Pei <[email protected]> Date: Thu, 25 Nov 2021 15:06:32 +1100 Subject: [PATCH] Adding a facility to resume from where the playback left at. - A custom option emms-playing-time-resume-from-last-played, default to nil, that resumes to the playing time when the track is started again. - Internally, emms-playing-time will update the playing-time property of the track, and reset it to nil when a track is finished. --- emms-playing-time.el | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/emms-playing-time.el b/emms-playing-time.el index e2a02fb..5a674b6 100644 --- a/emms-playing-time.el +++ b/emms-playing-time.el @@ -65,6 +65,11 @@ Valid styles are `time' (e.g., 01:30/4:20), and `downtime' (e.g. -03:58)." :type 'symbol) +(defcustom emms-playing-time-resume-from-last-played nil + "If set to Non-nil, emms will resume / seek to + the last playing time when the track is started again." + :type 'boolean) + ;;; Emms Playing Time @@ -123,6 +128,15 @@ and `downtime' (e.g. -03:58)." (declare (obsolete emms-playing-time-mode "Apr 2021")) (emms-playing-time-mode (if (and arg (> arg 0)) 1 -1))) +(defun emms-playing-time-track-reset () + (emms-track-set (emms-playlist-current-selected-track) + 'playing-time nil)) + +(defun emms-playing-time-maybe-seek-to-last-played () + (when-let ((last-playing-time + (emms-track-get (emms-playlist-current-selected-track) + 'playing-time))) + (emms-seek-to last-playing-time))) (define-minor-mode emms-playing-time-mode "Turn on emms playing time if ARG is positive, off otherwise. @@ -144,19 +158,28 @@ could call `emms-playing-time-enable-display' and (emms-playing-time-mode-line) (add-hook 'emms-player-started-hook #'emms-playing-time-start) (add-hook 'emms-player-stopped-hook #'emms-playing-time-stop) + (add-hook 'emms-player-finished-hook + #'emms-playing-time-track-reset) (add-hook 'emms-player-finished-hook #'emms-playing-time-stop) (add-hook 'emms-player-paused-hook #'emms-playing-time-pause) (add-hook 'emms-player-seeked-functions #'emms-playing-time-seek) - (add-hook 'emms-player-time-set-functions #'emms-playing-time-set)) + (add-hook 'emms-player-time-set-functions #'emms-playing-time-set) + (when emms-playing-time-resume-from-last-played + (add-hook 'emms-player-started-hook + #'emms-playing-time-maybe-seek-to-last-played))) (setq emms-playing-time-display-mode nil) (emms-playing-time-stop) (emms-playing-time-restore-mode-line) (remove-hook 'emms-player-started-hook #'emms-playing-time-start) (remove-hook 'emms-player-stopped-hook #'emms-playing-time-stop) (remove-hook 'emms-player-finished-hook #'emms-playing-time-stop) + (remove-hook 'emms-player-finished-hook + #'emms-playing-time-track-reset) (remove-hook 'emms-player-paused-hook #'emms-playing-time-pause) (remove-hook 'emms-player-seeked-functions #'emms-playing-time-seek) - (remove-hook 'emms-player-time-set-functions #'emms-playing-time-set))) + (remove-hook 'emms-player-time-set-functions #'emms-playing-time-set) + (remove-hook 'emms-player-started-hook + #'emms-playing-time-maybe-seek-to-last-played))) ;;;###autoload (define-minor-mode emms-playing-time-display-mode @@ -180,6 +203,8 @@ could call `emms-playing-time-enable-display' and (defun emms-playing-time-display () "Display playing time on the mode line." (setq emms-playing-time (round (1+ emms-playing-time))) + (emms-track-set (emms-playlist-current-selected-track) + 'playing-time emms-playing-time) (setq emms-playing-time-string (if (null emms-playing-time-display-mode) "" -- 2.34.0
--
Best,
Yuchen
PGP Key: 47F9 D050 1E11 8879 9040 4941 2126 7E93 EF86 DFD0
<https://ypei.me/assets/ypei-pubkey.txt>
signature.asc
Description: PGP signature
