aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/emms.texinfo6
-rw-r--r--emms-player-mpv.el56
2 files changed, 32 insertions, 30 deletions
diff --git a/doc/emms.texinfo b/doc/emms.texinfo
index 2f7440e..d3e30cf 100644
--- a/doc/emms.texinfo
+++ b/doc/emms.texinfo
@@ -546,11 +546,13 @@ value of @var{emms-source-file-default-directory}.
@end defun
@defun emms-play-url url
A source for an @var{url} - for example, for streaming over http,
-playing over sftp, or even playing local files (with file:// scheme)!
+playing over sftp, or playing local files (with the ``file://''
+scheme).
@end defun
@defun emms-add-url url
A source for an @var{url} - for example, for streaming over http,
-playing over sftp, or even playing local files (with file:// scheme)!
+playing over sftp, or playing local files (with the ``file://''
+scheme).
@end defun
@defun emms-play-playlist playlist
A source for the M3u or PLS playlist format from the file @var{playlist}.
diff --git a/emms-player-mpv.el b/emms-player-mpv.el
index 2659d55..e4a8ceb 100644
--- a/emms-player-mpv.el
+++ b/emms-player-mpv.el
@@ -60,6 +60,7 @@
(require 'emms)
(require 'emms-player-simple)
+(require 'emms-playing-time)
(require 'json)
(require 'cl-lib)
@@ -655,6 +656,12 @@ potential duplication if used for same properties from different functions."
(emms-player-mpv-debug-msg "idle-check (stopped=%s)" emms-player-mpv-stopped)
(unless emms-player-mpv-stopped (emms-player-stopped)))
+(defun emms-player-mpv-event-playing-time-sync ()
+ "Request and update `emms-playing-time' after playback seek/restart or unpause."
+ (emms-player-mpv-ipc-req-send '(get_property time-pos)
+ #'(lambda (pos err)
+ (unless err (emms-playing-time-set pos)))))
+
(defun emms-player-mpv-event-handler (json-data)
"Handler for supported mpv events, including property changes.
Called before `emms-player-mpv-event-functions' and does same thing as these hooks."
@@ -665,7 +672,17 @@ Called before `emms-player-mpv-event-functions' and does same thing as these hoo
;; and don't correspond to actual playback state.
(unless (emms-player-mpv-proc-playing-p)
(emms-player-mpv-proc-playing t)
- (emms-player-started emms-player-mpv)))
+ (emms-player-started emms-player-mpv))
+ (emms-player-mpv-event-playing-time-sync))
+ ("pause"
+ (unless emms-player-paused-p
+ (setq emms-player-paused-p t)
+ (run-hooks 'emms-player-paused-hook)))
+ ("unpause"
+ (emms-player-mpv-event-playing-time-sync)
+ (when emms-player-paused-p
+ (setq emms-player-paused-p nil)
+ (run-hooks 'emms-player-paused-hook)))
("end-file"
(when (emms-player-mpv-proc-playing-p)
(emms-player-mpv-proc-playing nil)
@@ -689,7 +706,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 +755,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))))))