4

I am trying to add a local file to mpd ( through mpc ) and play it . my platform is OpenWRT embedded linux .

so, from the man page, it states:

mpc add <file>   Add a song to the current playlist

if i do:

root@OpenWrt:~/.mpd# mpc add /usr/share/baresip/ring.wav 
error adding /usr/share/baresip/ring.wav: directory or file not found

or if i do:

root@OpenWrt:~/.mpd# mpc add file:///usr/share/baresip/ring.wav 
error adding file:///usr/share/baresip/ring.wav: Access denied

what exactly is the correct syntax here? the man page is really not very clear for mpc / mpd .

1

2 Answers 2

10

Your second attempt was almost right. The problem you had was that mpd will only allow file: URLs to be passed to it via a local connection, which it enforces by requiring you to connect on its unix-domain socket. So, in your mpd.conf you need to have a line like this:

bind_to_address     "/run/mpd/socket"

(depending on your system you may want to change /run to /var/run -- the version I quote is correct for recent versions of debian or ubuntu but others may be different).

Then, you need to set up your environment to point to that socket:

export MPD_HOST=/run/mpd/socket

when you do this, mpc add or mpc insert can successfully accept a file: URL:

$ mpc insert "file:///data/incoming/files/111_scorpions_-_the_zoo.mp3"
$ mpc next
Scorpions - The Zoo
[playing] #23/39   0:00/5:30 (0%)
volume: n/a   repeat: off   random: off   single: off   consume: off
$
5
  • On a mac with mpd installed through brew, I can't look up the unix socket in the typical /private/var/run location or anywhere else in the system. Should I look into generating a unix socket myself? Jun 3, 2018 at 15:24
  • 1
    @SviatoslavZalishchuk - yes; without an mpd.conf file (and as far as I can see the install script for 'brew' doesn't produce one) it will default to not generating a unix socket; you'll need to create a config file and tell it where to put the socket.
    – Jules
    Jun 3, 2018 at 16:07
  • Thanks for the prompt reply. Btw, is there a way to generate it from the shell? Or it can only be done through system layer with C/python/etc..? Jun 3, 2018 at 16:34
  • 1
    with an appropriate config file (see github.com/andrewrk/mpd/blob/master/doc/mpdconf.example for an example file to start from and man mpd.conf for documentation), mpd will create the socket itself.
    – Jules
    Jun 3, 2018 at 16:54
  • Yep, it did indeed. Previously when I tried to write that into /private/var/run/mpd.socket it apparently failed due to insufficient permissions, but gave "Connection Refused" instead. I have configured that to write the socket into user's home directory, set MPD_HOST, MPD_PORT variables to be exported in my .bashrc, so that they could be picked up by mpc and referenced in ncmpcpp. Now everything is in order, ncmpcpp manages the playlist and I configured ranger to open audio mime type files with mpc by default using the "mpc insert "/path/" && mpc next" trick. Thank you, Jules! Jun 4, 2018 at 10:44
4

i did not find out how to play wav..but i forgot i found the solution (for mp3) and posted it here: https://forum.openwrt.org/viewtopic.php?id=41022

however, since stackoverflow always shows up top on google search i am pasting the same solution here in case it helps someone as well :

/etc/mpd.conf should be something approximately like this:

music_directory        "/tmp"
playlist_directory        "~/.mpd/playlists"
db_file            "~/.mpd/database"
log_file            "/tmp/mpdlog"
pid_file            "~/.mpd/pid"
state_file            "~/.mpd/state"
sticker_file            "~/.mpd/sticker.sql"

user                "root"
group                "root"
bind_to_address "127.0.0.1"


log_level            "verbose"
auto_update    "yes"
auto_update_depth "3"
follow_outside_symlinks    "yes"
follow_inside_symlinks        "yes"

and then:

  1. /etc/init.d/mpd restart
  2. copy MP3 ( wav does not seem to work ) file to /tmp folder ( because music directory is the /tmp folder )
  3. mpc update
  4. mpc add file.mp3 ( adding /tmp/file.mp3 will NOT work )
  5. mpc play
4
  • 2
    wjy music directory setup to /tmp ?
    – realtebo
    Mar 6, 2015 at 18:59
  • 1
    @realtebo this is running on carambola dev board ( 8devices.com/carambola ) which has a large amount of flash memory but very little ROM memory. so i keep the music files on the /tmp directory and re-download them before playing Mar 7, 2015 at 5:22
  • 1
    copying a file just to play it might be a work around, but it's not a solution. I have files all over the place and different users. Apr 15, 2015 at 10:04
  • 1
    +1 to @Nikodemus comment. I know that mpd can play an arbitrary file, because you can make it do it via ncmpncpp, but like the OP, I'm looking for a command line way to do it, not a TUI program.
    – Jules
    Jun 4, 2016 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.