emms-help
[Top][All Lists]
Advanced

[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: Thu, 25 Nov 2021 15:10:49 +1100
User-agent: mu4e 1.4.13; emacs 27.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

- --=-=-=
Content-Type: text/plain; format=flowed


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.


- --=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0001-Adding-a-facility-to-resume-from-where-the-playback-.patch
Content-Transfer-Encoding: quoted-printable

From=20fd37f9c452d615e42c2768a3a81a6700335f66d5 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 a=
t.

=2D 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.
=2D Internally, emms-playing-time will update the playing-time property
of the track, and reset it to nil when a track is finished.
=2D--
 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
=2D-- 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)
=20
+(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
=20
@@ -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)))
=20
+(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)))
=20
 (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)
=2D     (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)
=2D    (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)))
=20
 ;;;###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)
             ""
=2D-=20
2.34.0


- --=-=-=
Content-Type: text/plain; format=flowed


- -- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
           <https://ypei.me/assets/ypei-pubkey.txt>

- --=-=-=--
-----BEGIN PGP SIGNATURE-----

iIEEARYIACkWIQRH+dBQHhGIeZBASUEhJn6T74bf0AUCYZ8MyQscaGlAeXBlaS5t
ZQAKCRAhJn6T74bf0JtpAQDtfCA7Q8FAz12NLGHtAOOectaQap1Rff+tdC94+Dzd
lAEA4tLHFC4BLKZ1l3g1I+wIy5E9wMqHkwoV7jZoUot1vwA=
=2bXd
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]