emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/mpv f0da905fd3 06/50: implement pausing and inserting play


From: ELPA Syncer
Subject: [nongnu] elpa/mpv f0da905fd3 06/50: implement pausing and inserting playback position
Date: Tue, 28 Dec 2021 00:58:34 -0500 (EST)

branch: elpa/mpv
commit f0da905fd3fb66dd0c16a36e42072fd21dc682d1
Author: Johann Klähn <kljohann@gmail.com>
Commit: Johann Klähn <kljohann@gmail.com>

    implement pausing and inserting playback position
---
 mpv-mode.el | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/mpv-mode.el b/mpv-mode.el
index 1da08ed794..075a73ef05 100644
--- a/mpv-mode.el
+++ b/mpv-mode.el
@@ -1,4 +1,4 @@
-;;; mpv-mode.el --- control mpv for easy note-taking
+;;; mpv-mode.el --- control mpv for easy note-taking  -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2014  Johann Klähn
 
@@ -37,6 +37,10 @@
   "Name or path to the mpv executable."
   :type 'file)
 
+(defcustom position-format "%H:%M:%S"
+  "Format used for inserting playback position."
+  :type 'string)
+
 (defvar -process nil)
 (defvar -queue nil)
 
@@ -121,6 +125,28 @@ drops unsolicited event messages."
             (error nil))
         (tq-queue-pop tq)))
     (-tq-process-buffer tq)))
+
+(defun pause ()
+  "Pause or unpause playback."
+  (interactive)
+  (-enqueue '("get_property" "pause")
+            (lambda (paused)
+              (-enqueue
+               `("set_property" "pause"
+                 ,(if (eq paused :json-false) t :json-false))
+               #'ignore))))
+
+(defun insert-playback-position ()
+  "Insert the current playback position at point."
+  (interactive)
+  (let ((buffer (current-buffer)))
+    (-enqueue '("get_property" "playback-time")
+              (lambda (time)
+                (let* ((secs (truncate time))
+                       (usecs (round (* 1000 (- time secs)))))
+                  (with-current-buffer buffer
+                    (insert (format-time-string position-format
+                                                `(0 ,secs ,usecs 0) t))))))))
 )
 
 (provide 'mpv-mode)



reply via email to

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