[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recovering playback state of multiple playlists and over multiple se
From: |
Yuchen Pei |
Subject: |
Re: Recovering playback state of multiple playlists and over multiple sessions |
Date: |
Tue, 30 Nov 2021 16:55:40 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Yuchen Pei <hi@ypei.me> writes:
> Something seems to be weird with my email client - sorry for the
> duplicate.
>
> Yoni Rabkin <yoni@rabkins.net> writes:
>
>> Yuchen Pei <hi@ypei.me> writes:
>>
>>> Yoni Rabkin <yoni@rabkins.net> writes:
>>>
>>>> Mike Kazantsev <mk.fraggod@gmail.com> writes:
>>>>
>>>>> On Wed, 20 Oct 2021 08:35:07 -0400
>>>>> Yoni Rabkin <yoni@rabkins.net> wrote:
>>>>>
>>>>>
>>>>> Maybe emms can just always store/update emms-playing-time on the
>>>>> track
>>>>> in playlist?
>>>>>
>>>>> That'd also double as "last stopped time" without adding any
>>>>> really
>>>>> new
>>>>> concepts, and there's 'info-playing-time for total duration there
>>>>> already.
>>>>>
>>>>>
>>>>> 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. stdout
>>>>> status line) can just cache it in some value.
>>>>>
>>>>> But if this is not implemented for backend, I'd think that
>>>>> fallback
>>>>> to
>>>>> emms-playing-time would seem reasonable, and then why not just
>>>>> always
>>>>> 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 to
>> welcome sojourning code.
>
> Please find attached a patch to add this facility and let me know what
> you think.
As discussed on IRC, please also find the change in a new branch in the
git repo called playing-time-resume:
https://git.savannah.gnu.org/cgit/emms.git/commit/?h=playing-time-resume&id=53ccdbc5dc896448cdaf7daf233b2274a9e17868
>
> From fd37f9c452d615e42c2768a3a81a6700335f66d5 Mon Sep 17 00:00:00 2001
> From: Yuchen Pei <hi@ypei.me>
> 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