3.3.1 Simple Commands

Once you’ve established a connection, send a command via elmpd-send. For instance,

(let ((conn (elmpd-connect :host "localhost")))
  (elmpd-send conn "play"))

will send the “play” command to the MPD instance on localhost at port 6600 (assuming no Unix socket). Note that this code will likely return before anything actually happens. As mentioned above, elmpd-connect returns immediately after creating the network process; it only reads & parses the MPD greeting asynchronously. Likewise, elmpd-send only queues up the “play” command; it will actually be sent & its response read in the background.

If you’d like to do something with the response, you can provide a callback:

(let ((conn (elmpd-connect :host "localhost")))
  (elmpd-send 
   conn
   "getvol"
   (lambda (_conn ok rsp)
     (if ok (message "volume is %s" (substring rsp 7))
       (error "Failed to get volume: %s" rsp)))))

The callback is invoked with the elmpd-connection on which the command was sent, a boolean indicating success or failure of the command, and either the server response (on success) or the server error message (on failure).