[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emms-help] Restore playback position
From: |
Pierre Neidhardt |
Subject: |
[emms-help] Restore playback position |
Date: |
Mon, 23 Oct 2017 23:55:26 +0100 |
User-agent: |
mu4e 0.9.18; emacs 25.2.1 |
The current playback position is stored in `emms-playing-time' so I
naively added that variable to `desktop-globals-to-save' hoping it would
restore it on next Emacs startup.
Sadly emms-start does not have an `&optional seek-to', so it always
starts playing from the beginning when `emms-start' is called.
Of course we could call `emms-player-seek-to time-save-by-desktop', the
problem is that the player is started asynchronously and we need to wait
for it to be ready before we can start seeking.
How do we do that? My current workaround is to `sleep-for` 300ms. Not
pretty.
Here is my current, brittle implementation:
(with-eval-after-load 'desktop
(add-to-list 'desktop-globals-to-save 'emms-playing-time)
(when (emms-playlist-current-selected-track)
(let ((time emms-playing-time))
(setq emms-playing-time 0) ; Don't disturb the time display.
(and (memq 'emms-player-mpv emms-player-list)
(executable-find "mpv")
(push "--mute=yes" emms-player-mpv-parameters))
(emms-start)
(sleep-for 0 300) ; This is required for the player might not be ready
yet.
;; TODO: This 'sleep-for' is a kludge and upstream should provide a
provision for it.
(with-demoted-errors "EMMS error: %S" (emms-player-seek-to time))
(and (memq 'emms-player-mpv emms-player-list)
(executable-find "mpv")
(pop emms-player-mpv-parameters)
(call-process-shell-command (emms-player-mpv--format-command "mute")
nil nil nil))
(emms-pause))))
Let me know if I'm missing something. If not, I propose we add
`&optional seek-to' to `emms-start' so that players can add a playback
position as parameters when they start.
Cheers!
--
Pierre Neidhardt
Better to be nouveau than never to have been riche at all.
- [emms-help] Restore playback position,
Pierre Neidhardt <=