From 770e3339cbc5e7c70ac15495c86419d9b2b5982f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20Casenave-P=C3=A9r=C3=A9?= Date: Thu, 16 Jun 2011 18:58:15 +0900 Subject: [PATCH] first commit Only play / pause are available. streaming is also available as at very simple stage. --- ido-mpc.el | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ido-mpc.el diff --git a/ido-mpc.el b/ido-mpc.el new file mode 100644 index 0000000..b628c05 --- /dev/null +++ b/ido-mpc.el @@ -0,0 +1,87 @@ +(require 'libmpdee) + +(defgroup ido-mpc nil + "customize group for ido-mpc." + :group 'external + :group 'applications + :group 'multimedia) + +(defcustom ido-mpc-server-url (or (getenv "MPD_HOST") "localhost") + "The MPD server that we should connect to." + :type 'string + :group 'ido-mpc) + +(defcustom ido-mpc-server-port (or (getenv "MPD_PORT") 6600) + "The port of the MPD server." + :type 'integer + :group 'ido-mpc) + +(defcustom ido-mpc-server-password nil + "The password for the MPD server." + :type '(choice (const :tag "None" nil) + string) + :group 'ido-mpc) + +(defcustom ido-mpc-stream-url nil + "The url of the stream to play when asking MPD to start." + :type '(choice (const :tag "None" nil) + string) + :group 'ido-mpc) + +(defcustom ido-mpc-stream-program "mplayer" + "The program to launch to play the stream." + :type '(choice (const :tag "None" nil) + string) + :group 'ido-mpc) + +(defcustom ido-mpc-check-interval 1 + "How often to check to see whether MusicPD has advanced to the +next song. This may be an integer or nil. If set to nil, this +check will not be periodically performed." + :type '(choice (const :tag "Disable check" nil) + integer) + :group 'ido-mpc) + +(defvar ido-mpc-conn nil) +(defvar ido-mpc-state nil) + +(defun ido-mpc-connect () + (interactive) + (setq ido-mpc-conn (mpd-conn-new ido-mpc-server-url + ido-mpc-server-port + 1 nil)) + (when ido-mpc-server-password + (mpd-set-password ido-mpc-conn ido-mpc-server-password)) + (ido-mpc-update-state)) + +(defun ido-mpc-update-state () + (setq ido-mpc-state (plist-get (mpd-get-status ido-mpc-conn) 'state))) + +(defun ido-mpc-stream-play () + (interactive) + (when (and ido-mpc-stream-url ido-mpc-stream-program ido-mpc-state) + (start-process "mpc-stream" nil ido-mpc-stream-program ido-mpc-stream-url))) + +(defun ido-mpc-play (&optional pos) + (interactive) + (unless ido-mpc-conn + (ido-mpc-connect)) + (if pos + (mpd-play ido-mpc-conn pos) + (mpd-play ido-mpc-conn)) + (ido-mpc-update-state) + (ido-mpc-stream-play)) + +(defun ido-mpc-pause () + (interactive) + (unless ido-mpc-conn + (ido-mpc-connect)) + (if (eq ido-mpc-state 'play) + (mpd-pause ido-mpc-conn t) + (if (eq ido-mpc-state 'stop) + (ido-mpc-play) + (mpd-pause ido-mpc-conn nil))) + (ido-mpc-update-state) + (ido-mpc-stream-play)) + +(provide 'ido-mpc)