How to Stream MPD and Setup Mpdroid

Published 2016-04-28 on Anjan's Homepage

MPD is great for handling a large music collection. It even has a feature where it can stream your music output over http. However, I found that there wasn't a good guide on setting http streaming up. Furthermore, I found a work-around to a bug in mpdroid that no google search revealed. Therefore, I thought that writing a guide on setting up http streaming would help alot of people out. Here's what I did to setup mpd and mpdroid:

1 Installing MPD

Start by installing mpd and mpc on your selected distribution. On debian it would be:

sudo apt-get install mpd mpc

Then, make a new user to run mpd so you don't have to run mpd as root:

sudo adduser mpdstream

Switch to the new user:

su - mpdstream

Create the files for mpd's data and config:

mkdir .mpd
mkdir .mpd/playlists
touch .mpd/{mpd.conf,mpd.pid,mpd.db,mpdstate,mpd.log}

Open .mpd/config in your favourite text editor and copy paste the following config in there:

music_directory "/mnt/AAE0DC50E0DC247B/Music"
playlist_directory "/home/mpdstream/.mpd/playlists"
db_file      "/home/mpdstream/.mpd/mpd.db"
log_file      "/home/mpdstream/.mpd/mpd.log"
pid_file      "/home/mpdstream/.mpd/mpd.pid"
state_file     "/home/mpdstream/.mpd/mpdstate"

audio_output {
     type  "alsa"
     name  "whatever you want"
     mixer_type "software"
     mixer_control "PCM"

}

audio_output {    
    type        "httpd"    
    name        "My HTTP Stream"    
    encoder     "lame"          # optional, vorbis or lame    
    port        "8001"    
    quality     "5.0"           # do not define if bitrate is defined    
#   bitrate     "320"           # do not define if quality is defined    
#   format      "44100:16:1"    
}

filesystem_charset             "UTF-8"
user                "mpdstream"
password                        "YOURPASSWORD@read,add,control,admin"
bind_to_address         "0.0.0.0"

I will only explain the options you will need to change in order to ensure everything works. If you'd like to learn about the other options I entered, please read the documentation for mpd.

music_directory "/mnt/AAE0DC50E0DC247B/Music"

Replace /mnt/AAE0DC50E0DC247B/Music with your music directory.

type "alsa"

Enter your audio output (alsa or pulse).

The second audio output defines the settings for the web output of mpd. Mpd supports playing to multiple outputs so the alsa/pulse output and httpd output can coexist in the same config file.

encoder "lame"

I will only go over how to use lame in this guide as it is the most common, it is the most likely encoder to work with your phone (see mpdroid setup), and it is the easiest to install.

port "8001"

Change this if you want and make note of it.

quality "5.0"

This quality integer is a good compromise for me when it comes to bandwidth used vs. quality.

password "YOURPASSWORD@read,add,control,admin"

Finally, set your password where it says YOURPASSWORD before the "@read,add,control,admin". If my password was spiderman, this line would become:

password "spiderman@read,add,control,admin"

Write and close the config file.

Install lame by running:

sudo apt-get install lame

Make sure you allow the ports for httpd and mpd through your firewall. In my case, the httpd port is 8001 and the mpd port is 6000. So, I ran:

sudo ufw allow 6600/tcp
sudo ufw allow 8001/tcp

Also, if you'd like to use mpd httpd outside of your network, forward these ports in your router.

Make sure no instances of mpd are running by typing killall mpd into the terminal.

Then, type mpd into terminal in order to to start mpd as the user mpdstream.

2 Setting up Mpdroid

Download mpdroid from playstore

Tap on Default connection settings

For Host, enter the ip of your router if you're outside your network. If you're inside your network, enter the ip of the computer you're running the mpd server on.

For Port, enter your mpd server port (Since I didnt change it in my config, it's 6600)

Enter the password for your mpd server

For Streaming host, enter the same ip as you entered for Host.

For Streaming port, enter your mpd streaming port (In my case, it's 8001).

For streaming url suffix enter mpd.mp3 if you're using lame as this guide describes. Enter mpd.ogg if you're using vorbis.

Press back a couple times once you are done configuring and it will try to connect to your server.

Once connected, try to play something and tap the bottom bar with the title of the current song playing. Click the three dots on the top right of the screen and check streaming. If sound doesnt play, know that this is a common bug on android. However, I came up with a work-around:

3 No sound from Mpdroid when streaming

Download vlc from the playstore.

Tap the three horizontal lines on the top left of vlc and tap stream.

For network address, type http://YOUR_STREAMING_HOST_IP:YOUR_STREAMING_PORT/mpd.mp3

In my case, this would be:

http://192.168.1.100:8001/mpd.mp3 if I was on my internal network.

Now, when you have a song playing in mpdroid, you can tap the ip of your server to listen to it. You treat mpdroid as the remote to pause/change songs and vlc as the app that plays the streamed data.

4 Reccomended further readings:

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~anjan/public-inbox@lists.sr.ht [mailing list etiquette]

Articles from blogs I follow around the net

These articles/blogs do not represent my own opinions or views.

A few ways to make money in FOSS

I work on free and open-source software full time, and I make a comfortable living doing it. And I don’t half-ass it: 100% of my code is free and open-source. There’s no proprietary add-ons, no periodic code dumps, just 100% bona-fide free and open source so…

via Drew DeVault's blog November 20, 2020

How to Make Biomass Energy Sustainable Again

From the Neolithic to the beginning of the twentieth century, coppiced woodlands, pollarded trees, and hedgerows provided people with a sustainable supply of energy, materials, and food.

via LOW←TECH MAGAZINE September 20, 2020

Eshell versus M-x shell

I’ve used and defended Eshell for years. Sadly, Eshell has some long standing issues that I grew tired of in the long run. So I’ve decided to switch to M-x shell and see how much of my Eshell workflow I could port. Language and the underlying shell pr…

via Pierre Neidhardt's homepage June 26, 2020

Generated by openring