Turn your Pine64 into a music server with mpd
#1
Hi together!

This topic is structured into a few categories.
• Prepare your Pine64
• Installing and setup MPD
• Fix sound problems with alsamixer
• Installing und setup Samba
• Control your MPD via IR remote control
• My own setup





» Prepare your Pine64

What do you need?
- Pine64 board.
- Speakers via audiojack.
- Install the latest Ubuntu image by longsleep.

What you'll get?
- A music server which can be controlled via Windows, Linux and Android.


First of all:
Download the latest Ubuntu image by longsleep.
Overview of all Ubuntu images powered by longsleep

I downloaded the following image:
xenial-pine64-bspkernel-20161218-1

After you have downloaded and burned the image on your micro sdcard you need to apply some pre requirements.



If you just downloaded the Ubuntu image you have to resize the partitions of your microsd card.
Just enter this command:
Code:
resize_rootfs.sh



Next step: Update the software of Pine64.
Code:
pine64_fix_whatever.sh
pine64_update_kernel.sh
pine64_update_uboot.sh
apt-get update
apt-get upgrade



Ok, all pre requirements are given now.




» Installing und setup MPD

Let's install mpd!
Code:
apt-get install mpc mpd
mpc (Music Player Command, client) is a command line program to manage mpd (Music Player Daemon, server).



Fix permissions of mpd directories:
Code:
chmod 770 /var/lib/mpd/music/ /var/lib/mpd/playlists/
chown -R mpd:audio /var/lib/mpd/music/ /var/lib/mpd/playlists/



Apply my config for mpd:
Code:
cat <<EOF >/etc/mpd.conf
music_directory      "/var/lib/mpd/music"
playlist_directory   "/var/lib/mpd/playlists"
db_file              "/var/lib/mpd/tag_cache"
log_file             "/var/log/mpd/mpd.log"
pid_file             "/run/mpd/pid"
state_file           "/var/lib/mpd/state"
sticker_file         "/var/lib/mpd/sticker.sql"
user                 "mpd"
port                 "6600"
log_level            "verbose"
restore_paused       "yes"
auto_update          "yes"
auto_update_depth    "3"
filesystem_charset   "UTF-8"
id3v1_encoding       "UTF-8"

input {
    plugin          "curl"
}

audio_output {
    type            "alsa"
    name            "My ALSA Device"
    mixer_type      "software"
}
EOF
The configuration of mpd is done.



Now activate audio output via 3.5 audiojack!
But please note:
The 3.5 audiojack will be the default device for all audio output with these configs!
Code:
cat <<EOF >/etc/modules-load.d/pine64-audiojack.conf
sunxi_codec
sunxi_i2s
sunxi_sndcodec
EOF
Code:
cat <<EOF >/etc/asound.conf
pcm.!default {
       type plug slave {
               pcm "hw:1,0"
               }
}

ctl.!default {
       type hw
       card 1
}
EOF



Reboot your Pine64 to apply changes of sound cards.
Code:
reboot



Just copy all your music files into the following directory:
Code:
/var/lib/mpd/music
I'll explain how to copy files from your Windows machine easily to your mpd server at the end of this post!



Take note that ownerships are correct!
If not, apply them.
Code:
chown -R mpd:audio /var/lib/mpd/music/



Update the music database of mpd with mpc.
Code:
mpc update



Alright, you're done!

Feel free to manage your mpd server with different mpd clients!
These are my favourites:
• Linux & Windows: Gnome Music Player Client
• Android: MPD ControlDroid MPD Client





» Fix sound problems with alsamixer

Normally there should be no problems with sound if you are using the latest Ubuntu image by longsleep.
So, you are advised to check the following settings in alsamixer.
Code:
alsamixer
Code:
Unmute "Headphone" with toogling "m"
Set "ADCL Mux" to "DMIC".
Set "ADCR Mux" to "DMIC".
Set "AIF1 DAC timeslot 0 volume" to 85.
Set "AIF1IN0L Mux" to "AIF1_DA0L".
Set "AIFIN0R Mux" to "AIF1_DA0R".
Unmute "DACL Mixer ADCL" with toogling "m"
Unmute "DACL Mixer AIF1DA0L" with toogling "m"
Unmute "DARC Micer ADCR" with toogling "m"
Unmute "DACR Mixer AIFDA0R" with toogling "m"
Set "digital volume" to "0".
Set "headphone volume" to "75".





» Installing und setup Samba

How to copy your files from your Windows machine to your Pine64 - Use SFTP or... Let's install Samba!

Code:
apt-get install samba-common samba



Create a Samba user to manage your files:
Code:
smbpasswd -a mpd
Just set a password for mpd user.



Apply my config to login via Samba with mpd user:
Code:
cat <<EOF >/etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
security = user
dns proxy = no

[mpd]
path = /var/lib/mpd
valid users = mpd
force user = mpd
force group = audio
create mask = 0660
directory mask = 0770
browsable = yes
writable = yes
EOF



Restart Samba.
Code:
/etc/init.d/samba restart
Now you are able to copy your music very easily from Windows to your Pine64.



Just add a "Network ressource" on Windows with the following path:
Code:
\\ip-address-of-pine64\mpd
Username: mpd
Password: You have choosen it with "smbpasswd -a mpd"



[Image: mpdbsufd.png]




» Control your MPD via IR remote control

Control your MPD server with the official IR remote control by Pine64!


You need to install "keybinder", to re-mapping the keys of your IR remote control to execute commands.
Code:
apt-get install unzip gcc make
cd ~
mkdir keybinder
cd keybinder
wget https://github.com/elopez/keybinder/archive/master.zip
unzip master.zip
cd keybinder-master/
make
make install
cd ~
rm -r ~/keybinder



Use "evtest" to determine the event input of IR receiver:
Code:
apt-get install evtest
evtest
Choose the event number with "sunxi_ir_recv".
The event number depends of the plugged in usb devices!!!



Code:
root@pine64:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      sunxi-keyboard
/dev/input/event1:      axp81x-supplyer
/dev/input/event2:      sunxi-ths
/dev/input/event3:      audiocodec sunxi Audio Jack
/dev/input/event4:      sunxi_ir_recv
/dev/input/event5:      MCE IR Keyboard/Mouse (sunxi-rc-recv)



Now press a few buttons on your IR remote control.
You should see some entries like...
Code:
Testing ... (interrupt to exit)
Event: time 1490184760.781095, type 4 (EV_MSC), code 4 (MSC_SCAN), value 40400d
Event: time 1490184760.781095, type 1 (EV_KEY), code 13 (KEY_EQUAL), value 1
Event: time 1490184760.781095, -------------- SYN_REPORT ------------
Event: time 1490184761.023186, type 1 (EV_KEY), code 13 (KEY_EQUAL), value 0
Event: time 1490184761.023186, -------------- SYN_REPORT ------------
Event: time 1490184761.793386, type 4 (EV_MSC), code 4 (MSC_SCAN), value 404010
Event: time 1490184761.793386, type 1 (EV_KEY), code 16 (KEY_Q), value 1
Event: time 1490184761.793386, -------------- SYN_REPORT ------------
Event: time 1490184762.043188, type 1 (EV_KEY), code 16 (KEY_Q), value 0
Event: time 1490184762.043188, -------------- SYN_REPORT ------------
Event: time 1490184762.734733, type 4 (EV_MSC), code 4 (MSC_SCAN), value 404011
Event: time 1490184762.734733, type 1 (EV_KEY), code 17 (KEY_W), value 1
Event: time 1490184762.734733, -------------- SYN_REPORT ------------
Event: time 1490184762.983185, type 1 (EV_KEY), code 17 (KEY_W), value 0
Event: time 1490184762.983185, -------------- SYN_REPORT ------------
Event: time 1490184763.508206, type 4 (EV_MSC), code 4 (MSC_SCAN), value 40400e
Event: time 1490184763.508206, type 1 (EV_KEY), code 14 (KEY_BACKSPACE), value 1
Event: time 1490184763.508206, -------------- SYN_REPORT ------------
Event: time 1490184763.753183, type 1 (EV_KEY), code 14 (KEY_BACKSPACE), value 0
Event: time 1490184763.753183, -------------- SYN_REPORT ------------
Event: time 1490184764.026059, type 4 (EV_MSC), code 4 (MSC_SCAN), value 40400b
Event: time 1490184764.026059, type 1 (EV_KEY), code 11 (KEY_0), value 1
Event: time 1490184764.026059, -------------- SYN_REPORT ------------
Event: time 1490184764.273206, type 1 (EV_KEY), code 11 (KEY_0), value 0
Event: time 1490184764.273206, -------------- SYN_REPORT ------------



Now we can work with keybinder
Code:
keybinder /dev/input/eventX
X depends on the event number of your IR receiver!!!
You got the number by evtest.



Feel free to apply my config or create your own.
Code:
cat <<EOF >/etc/keybinder.conf
24,mpc volume +10   # Set the volume +10
23,mpc volume -10   # Reduce the volume -10
16,mpc prev         # Play previous track
17,mpc next         # Play next track
13,mpc toggle       # Play/Pause playback
69,mpc random       # De-/Activate random playback
77,shutdown -h now  # Shutdown the Pine64
EOF

[Image: ir_remote_controlwkus1.png]



Start keybinder automatically on boot.
Code:
(crontab -l ; echo "@reboot /usr/bin/screen -dmS keybinder /usr/local/bin/keybinder /dev/input/eventX")| crontab -
X depends on the event number of your IR receiver!!!




» My own setup

[Image: img_20170312_101912a4uj7.jpg] [Image: img_20170311_1211430aubd.jpg]  [Image: img_20170311_164216hwux7.jpg] [Image: img_20170311_212653b3uyo.jpg] [Image: img_20170311_212802wauce.jpg]
[Image: img_20170311_192506etu6v.jpg] [Image: img_20170312_1337249cu2d.jpg]


Have fun with it Smile


Best regards
Julian
My forum topics:
• Create a WiFi hotspot on Debian 8
• Turn your Pine64 into a music server with mpd
• Adjust brightness of LCD on Armbian Desktop with 1 click
• My cases for Pine64 (acryl, lego & wood)

• Pine 64 - DACH - Facebook page for german-speaking Pine64-fans.
#2
Great post Julian!
You can find me on IRC, Discord and Twitter


#3
Thanks on the good post.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pine64 as squeezebox touch replacement Learnincurve 12 30,462 01-13-2021, 02:11 AM
Last Post: Learnincurve
  Pine64 E-ink screen - Android projectileobjects 4 10,435 12-03-2020, 03:03 PM
Last Post: Silk
  Pine64 based IP KVM tuaris 0 4,263 08-06-2020, 12:05 AM
Last Post: tuaris
  Mastodon instance \ Nextcloud Server fearg 1 5,050 03-31-2020, 08:18 PM
Last Post: tllim
Information Pine64 Head Unit Zoidiano0 100 159,076 11-19-2019, 04:35 AM
Last Post: rogatip79
  PINE64 to allow use of SATA disk on network/FTP mwelbourne 10 17,589 11-18-2019, 04:09 PM
Last Post: evilbunny
  How to setup VNC on your Pine64 (Debian, SSH, headless) pine64nutz 20 46,370 04-16-2019, 08:00 AM
Last Post: hg6806
  Setup Pine64+ with OP-TEE stdys 0 3,846 09-13-2018, 03:23 PM
Last Post: stdys
  Plex server arghne 59 150,586 07-06-2018, 10:36 AM
Last Post: Moshe.Vazan
Information UEFI for Pine64 z4v4l 20 42,673 06-24-2018, 03:06 PM
Last Post: z4v4l

Forum Jump:


Users browsing this thread: 2 Guest(s)