/afb-mpdc

Music Player Daemon Client Binding

Primary LanguageCApache License 2.0Apache-2.0


Audio Client Binding for Music Daemon Player


MPDC (Music Player Daemon Client) is a standard AGL Application Framework binding. It works on AGL as well as on any modern Linux standard distribution. It provide API to play music, handle playlist, ... It it a work in progress and while not every simple function from MPD are exposed al critical one to build a demo should be in place.

MPDC support multiple clients and multiple servers. It is rely on MPD official client library and support command channel as well as event notifications. This last point allow AGL client to be notify of audio changes automatically (ex: new song).

MPDC can run as a standalone binder or may be merge with others audio bindings (e.g. run MPSC directly as an API of AAAA). It can also combine with a controller in case authorisation/policy would be needed.

Cloning Music Player Binding from Git


# Initial clone with submodules
git clone --recurse-submodules https://github.com/iotbzh/mpdc-binding

# Do not forget submodules with pulling
git pull --recurse-submodules https://github.com/iotbzh/mpdc-binding

Dependencies

See instructions for AGL Linux native dev packages at https://en.opensuse.org/LinuxAutomotive#Installation_AGL_Application_Framework

  • OpenSuse:

    • sudo zypper in agl-app-framework-binder
    • sudo zypper in libmpdclient-devel mpd
  • Ubuntu 16.04LTS

    • sudo apt install agl-app-framework-binder
    • sudo apt install libmpdclient-dev mpd

Quick start

  • Compile mpdc-binding

    • cd mpdc-binding
    • mkdir build && cd build
    • cmake ..
    • make
  • Create an Alsa Config for Music Player Daemon

    • Check conf.d/project/mpd.d/mpd-fulup-home.conf
    • Place config file somewhere (default mpd search location $HOME/.config/mpd/mpd.conf or /etc/mpd.conf)
    • Edit mpd.conf to reflect your configuration
  • Start MPD in debug mode

    • mpd --no-daemon --stderr -v path-to-your-mpd.conf
  • Start mpdc-binding

    • afb-daemon
  • Verify your Alsa Config

    • Make sure pulse does not preempt your sound card (pavucontrol/configuration/soundcard/off)
    • Install you asoundrc file (see sample in conf.d/project/alsa.d)
    • Assert that your Alsa/PCM is active example:speaker-test -DNavPCM -c2 -twav
      grep pcm ~/.asoundrc  # check your configure PCM
      speaker-test -Dhw:v1340 -c2 -twav        # check sound card
      speaker-test -DMixerPCM -c2 -twav        # check Alsa Mixer
      speaker-test -DNavSoftvolPCM -c2 -twav   # check Navigation Softvol
      speaker-test -DNavigation -c2 -twav      # WARNING: AAAA/control should be ready to respond
    
      Note: no need to reload Alsa for those test. ~.asoundrc is read for each new request
    
  • Note: For you initial test, you may want to use a richer graphical frontend like cantata(Qt). ** OpenSuse Binary Package https://software.opensuse.org/package/cantata

  • Check it works (list music repository)

    • mpc ls
    • mpc findadd filename 'music-filename.mp3' # warning should be fullname
    • mpc playlist # check your playlist contend
    • mpc play
    # Do not set MPD_PORT in environement to advoid further conflict
    export NAV_MPD=6002   # My Music Player Deamon Port
    - MPD_PORT=$NAV_MPD mpc ls   # List all files from my Music library
    - MPD_PORT=$NAV_MPD mpc output # list audio output
    
    - MPD_PORT=$NAV_MPD mpc findadd filename 'message-1.mp3' # add file to playlist
    - MPD_PORT=$NAV_MPD mpc playlist # list song in default playlist
    - MPD_PORT=$NAV_MPD mpc clear # clear all playlist
    
    - MPD_PORT=$NAV_MPD mpc play
    - MPD_PORT=$NAV_MPD mpc pause
    - MPD_PORT=$NAV_MPD mpc toggle
    
    

API

  • Search search the database for song,categories and optionally add them to play list

    • display(mandatory): field to be return by command eg: artist, title, filename, ...
    • query(optional): artist_name (should match with type)
    • target(optional) and array of [{type:xxx, content:yyy}]
    • add(optional): boolean (search and add to play list)
    • exact(optional): boolean (search substring or not)
    • example: {api:'mpdc',verb:'search', query={display:'artist', target={type:'genre', content:'folk'}}
  • Output select or return the output list from configuration. Take list:true as default

    • list(default:true) return the list of output with the enable/disable flag.
    • only(default:false) revers action for every non listed output
    • target:(default:none) json array of targeted outputs [{name:xxxx|id:??|all:true, enable:true/false}]
    • example: {api:'mpdc',verb:'output', only:true, target:[{name='zone-front',enable:true(default)}, ...], ...}
  • Control send control action to music daemon (except when specified control are simple boolean)

    • pause
    • resume
    • toggle "Toggles Play/Pause, plays if stopped"
    • next "Play the next song in the current playlist"
    • prev "Play the previous song in the current playlist"
    • play "[]", "Start playing at "
    • stop "Stop the currently playing playlists"
    • seek "[+-][HH:MM:SS]|<0-100>%", "Seeks to the specified position"
  • Playlist control playlist

    • current "Print current Playlist Queue"
    • name "[]", "Print content, multiple list name might be given as an array"
    • clear "Clear the current playlist"
    • shuffle "Shuffle the current playlist"
    • move " ", "Move song in playlist"
    • save "", "Save a playlist as "
    • load "", "Load as a playlist"
    • remove "", "Remove a playlist"
  • File Management

    • listsong [path] list all song from Daemon at given path (no path == list all)
  • Manage few administrative commands

    • update "[]", "Scan music directory for updates"
    • stat "Display statistics about MPD"
    • version "Report version of MPD"

Environement Variables

  • MPDC_NODEF_CONNECT by default MPDC will try to connect to Music Player Daemon default port on localhost. When MPDC_NODEF_CONNECT is et no connection is try at initialisation time and MPDC will wait for effective connection request. Note that MPDC support simultaneous connections to as many MPD you need (in demo sample config: Multimedia, Navigation, Emergency, ...).

Testing

  • Start a Music Player Daemon with default option (port 6600) check sample config in conf.d/project/mpd.d
  • Start MPDC in a standalone binder as described here after
cd build
cmake ..
make populate
afb-daemon --port=1234 --ldpaths=package/lib --workdir=. --roothttp=../htdocs --tracereq=common \
--token= --verbose --ws-server=unix:/var/tmp/afb-ws/mpdc

Note that we expose MPDC API for other binding to consume it. Check aaaa-demo that consume mpdc API. For test only you may connect directly on http://localhost:1234 to access test and monitoring pages. Condig to run/debug inside netbeans here