emms-help
[Top][All Lists]
Advanced

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

Re: [emms-help] [PATCH] mpv player


From: Yoni Rabkin
Subject: Re: [emms-help] [PATCH] mpv player
Date: Sat, 16 Sep 2017 11:37:34 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Petteri Hintsanen <address@hidden> writes:

> Hello,
>
> the attached patch adds support for mpv (http://mpv.io)
> It is mostly copy-paste from emms-player-mplayer.el and
> emms-player-simple.el

Thank you for doing this; we want to provide this in time for the next
release (4.4, slated for November).

Which version of mpv is currently being widely distributed? I know that
previous versions (for instance the version I have) don't yet support
the --input-ipc-server command. This also means that at the moment I
can't test this patch.

It would be good to check for the version and raise a error if the mpv
version is too old. I would also be happy for a documentation patch
which, among other things, describes what is the minimum version of mpv
that would work.

There is no need to support the older versions, as this is a problem
which will solve itself in time, and I think the --input-ipc-server
command is the way mpv will be moving forward.

The goal of all of this is to reduce frustration for people who will try
to use emms-player-mpv, but still have older versions of mpv for one
reason or another.

> The main difference from mplayer is that mpv has local socket IPC
> instead of stdin slave mode.  Therefore the code generates a temporary
> socket file for each player invocation, and carefully tries to remove
> that file after player exits.  A simpler version could use a fixed
> socket file, maybe via defcustom, but then concurrent mpv processes
> would get mixed up.  I am not sure if that rather theoretical risk
> warrants the complexity, though.

I would rather support the former over the latter, so the way you did it
is good.

> ---
>  lisp/emms-player-mpv.el | 120 
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 120 insertions(+)
>  create mode 100644 lisp/emms-player-mpv.el
>
> diff --git a/lisp/emms-player-mpv.el b/lisp/emms-player-mpv.el
> new file mode 100644
> index 0000000..dbfba7d
> --- /dev/null
> +++ b/lisp/emms-player-mpv.el
> @@ -0,0 +1,120 @@
> +;;; emms-player-mpv.el --- mpv support for EMMS
> +
> +;; Copyright (C) 2017 Free Software Foundation, Inc.
> +
> +;; Authors: Petteri Hintsanen <address@hidden>
> +
> +;; This file is part of EMMS.
> +
> +;; EMMS is free software; you can redistribute it and/or
> +;; modify it under the terms of the GNU General Public License
> +;; as published by the Free Software Foundation; either version 3
> +;; of the License, or (at your option) any later version.
> +
> +;; EMMS is distributed in the hope that it will be useful,
> +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;; GNU General Public License for more details.
> +
> +;; You should have received a copy of the GNU General Public License
> +;; along with EMMS; if not, write to the Free Software Foundation,
> +;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
> +
> +;;; Commentary:
> +
> +;; This provides a player that uses mpv (http://mpv.io).  It supports
> +;; pause and seeking.
> +
> +;;; Code:
> +
> +(require 'emms-player-simple)
> +
> +(defvar emms-player-mpv-socket-file nil
> +  "The local socket listened by mpv.")
> +
> +(defvar emms-player-mpv-network-process nil
> +  "Connection to the local socket of the current player.")
> +
> +(define-emms-simple-player mpv '(file url)
> +  (concat "\\`\\(http[s]?\\|mms\\)://\\|"
> +       (apply #'emms-player-simple-regexp
> +              emms-player-base-format-list))
> +  "mpv" "--audio-display=no" "--no-terminal")
> +
> +(define-emms-simple-player mpv-playlist '(streamlist)
> +  "\\`http[s]?://"
> +  "mpv" "--audio-display=no" "--no-terminal" "--playlist")
> +
> +(defun emms-player-mpv-delete-socket-file ()
> +  "Delete an obsolete socket file.
> +This function is added to several hooks to prevent stray socket
> +files."
> +  (ignore-errors (delete-file emms-player-mpv-socket-file))
> +  (setq emms-player-mpv-socket-file nil))
> +
> +(defun emms-player-mpv-ipc-process ()
> +  "Return a connection to the IPC socket of the current player.
> +Return an existing connection if one exists.  Otherwise set up a
> +new connection and return it."
> +  (if (process-live-p emms-player-mpv-network-process)
> +      emms-player-mpv-network-process
> +    (setq emms-player-mpv-network-process
> +          (make-network-process :name "mpv-ipc"
> +                                :family 'local
> +                                :remote emms-player-mpv-socket-file))))
> +
> +(defun emms-player-mpv-start-with-socket (track)
> +  "Start the player process."
> +  (setq emms-player-mpv-socket-file (make-temp-file "mpv-socket"))
> +  (emms-player-simple-start
> +   (emms-track-name track)
> +   'emms-player-mpv
> +   emms-player-mpv-command-name
> +   (append emms-player-mpv-parameters
> +           (list (concat "--input-ipc-server="
> +                         emms-player-mpv-socket-file)))))
> +
> +(defun emms-player-mpv-pause ()
> +  (process-send-string
> +   (emms-player-mpv-ipc-process)
> +   "pause\n"))
> +
> +(defun emms-player-mpv-seek (sec)
> +  (process-send-string
> +   (emms-player-mpv-ipc-process)
> +   (format "seek %d\n" sec)))
> +
> +(defun emms-player-mpv-seek-to (sec)
> +  (process-send-string
> +   (emms-player-mpv-ipc-process)
> +   (format "seek %d absolute\n" sec)))
> +
> +(emms-player-set emms-player-mpv
> +                 'start
> +                 'emms-player-mpv-start-with-socket)
> +
> +(emms-player-set emms-player-mpv
> +              'pause
> +              'emms-player-mpv-pause)
> +
> +(emms-player-set emms-player-mpv
> +                 'resume
> +                 'emms-player-mpv-pause)
> +
> +(emms-player-set emms-player-mpv
> +              'seek
> +              'emms-player-mpv-seek)
> +
> +(emms-player-set emms-player-mpv
> +              'seek-to
> +              'emms-player-mpv-seek-to)
> +
> +(add-hook 'emms-player-stopped-hook
> +          'emms-player-mpv-delete-socket-file)
> +(add-hook 'emms-player-finished-hook
> +          'emms-player-mpv-delete-socket-file)
> +(add-hook 'kill-emacs-hook
> +          'emms-player-mpv-delete-socket-file)
> +
> +(provide 'emms-player-mpv)
> +;;; emms-player-mpv.el ends here

-- 
   "Cut your own wood and it will warm you twice"



reply via email to

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