diff options
author | Mike Kazantsev <mk.fraggod@gmail.com> | 2021-10-19 21:57:37 +0500 |
---|---|---|
committer | fraggod@malediction <mk.fraggod@gmail.com> | 2021-10-19 21:57:37 +0500 |
commit | 12f7d295a3add2362d80132144d9ca8ea026f64c (patch) | |
tree | 833018e3ca45079fbf94b8552f40286568fe0bd7 | |
parent | f0da8453ae94aec630ad5b3395d6bc882ef0ae57 (diff) |
* emms-player-mpv.el: simplify current track duration updates by observing the property
-rw-r--r-- | emms-player-mpv.el | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/emms-player-mpv.el b/emms-player-mpv.el index 2659d55..53b25b4 100644 --- a/emms-player-mpv.el +++ b/emms-player-mpv.el @@ -689,7 +689,8 @@ Called before `emms-player-mpv-event-functions' and does same thing as these hoo (defun emms-player-mpv-info-meta-connect-func () "Hook function for `emms-player-mpv-event-connect-hook' to update metadata from mpv." - (emms-player-mpv-observe-property 'metadata)) + (emms-player-mpv-observe-property 'metadata) + (emms-player-mpv-observe-property 'duration)) (defun emms-player-mpv-info-meta-event-func (json-data) "Hook function for `emms-player-mpv-event-functions' to update metadata from mpv." @@ -737,32 +738,14 @@ Called before `emms-player-mpv-event-functions' and does same thing as these hoo (defun emms-player-mpv-info-duration-event-func (json-data) "Hook function for `emms-player-mpv-event-functions' to update track duration from mpv." (when - (string= (alist-get 'event json-data) - "playback-restart") - (emms-player-mpv-info-duration-check))) - -(defun emms-player-mpv-info-duration-check () - "Check whether current mpv track has reliable duration info and request it." - (emms-player-mpv-ipc-req-send '(get_property stream-end) - (lambda (pts-end err) - (if err - (unless (and (stringp err) - (string= err "property unavailable")) - (emms-player-mpv-ipc-req-error-printer pts-end err)) - (when pts-end - (emms-player-mpv-ipc-req-send '(get_property duration) - #'emms-player-mpv-info-duration-handler)))))) - -(defun emms-player-mpv-info-duration-handler (duration err) - "Duration property request handler to update it for current emms track." - (if err - (emms-player-mpv-debug-msg "duration-req-error: %s" err) - ;; Duration can be nil or 0 for network streams, depending on version/stream - (when (and (numberp duration) - (> duration 0)) - (let - ((duration (round duration)) - (track (emms-playlist-current-selected-track))) + (and + (string= (alist-get 'event json-data) "property-change") + (string= (alist-get 'name json-data) "duration")) + (let + ((duration (alist-get 'data json-data)) + (track (emms-playlist-current-selected-track))) + (when (and track (numberp duration) (> duration 0)) + (setq duration (round duration)) (emms-track-set track 'info-playing-time duration) (emms-track-set track 'info-playing-time-min (/ duration 60)) (emms-track-set track 'info-playing-time-sec (% duration 60)))))) |