Streaming with MPD and Icecast2

Kernels & Hardware, configuring network, installing services

Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-22 05:42

Alright. I've finally gotten the network share working and a test file uploaded to the Library in my fit-PC. I've installed mpd and icecast2 as well as mpc, though I'm not sure if I need that or not. I've found a number of tutorials for this process but they vary widely and are very inconsistent and often also very old. I don't know what I need to add to /etc/mpd.conf or /etc/icecast2/icecast.xml and what I don't need to add to those files.

Ultimately, I want to be able to stream multiple instances of mpd on the same IP on different ports, so a user could put my IP address and a port number into their music player and play a different stream based on whatever port they put in.

Some of the tutorials and walk-throughs I've looked at are:
https://wiki.debian.org/mpd
https://stmllr.net/blog/streaming-audio-with-mpd-and-icecast2-on-raspberry-pi/
https://wiki.archlinux.org/index.php/Icecast
https://dev.to/djemos/how-to-setup-a-streaming-multimedia-server-internet-radio-station-a2a
https://log.liminastudio.com/miscellaneous/streaming-mpd-to-icecast-as-mp3

As you can see, they're all very different. Some have the stream type set as "alsa" in the /etc/mpd.conf file and some have it set as "shout". I don't know that the difference is or which I should use.

Can someone shed some more light on this, please?
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Head_on_a_Stick » 2020-03-22 09:25

Looks like you don't need icecast at all: https://wiki.archlinux.org/index.php/Mu ... _streaming

Disclaimer: I've never actually tried this.
User avatar
Head_on_a_Stick
 
Posts: 11453
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-22 17:47

Hmmm. That's interesting.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-23 02:03

Nobody else has any ideas about this?

My /etc/mpd.conf file contains:
Code: Select all
music_directory         "/home/radio/Library"
playlist_directory              "/home/radio/Library/playlists"

Audio_output {
#       type            "shout"
        encoding        "mp3"
        type            "httpd"
        name            "My Radio"
        description     "My Radio"
        host            "localhost"
        mount           "/mpd.mp3"
        port            "8000"
        tags            "yes"
#       quality         "5.0"
        bitrate         "192"
        user            "<user>"

When I try to start the service:
Code: Select all
root@radio:~# service mpd start
Job for mpd.service failed because the control process exited with error code.
See "systemctl status mpd.service" and "journalctl -xe" for details.
root@radio:~# systemctl status mpd.service
● mpd.service - Music Player Daemon
   Loaded: loaded (/lib/systemd/system/mpd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-03-22 19:36:08 PDT; 48s ago
     Docs: man:mpd(1)
           man:mpd.conf(5)
           file:///usr/share/doc/mpd/user-manual.html
  Process: 648 ExecStart=/usr/bin/mpd --no-daemon $MPDCONF (code=exited, status=1/FAILURE)
 Main PID: 648 (code=exited, status=1/FAILURE)

Mar 22 19:36:07 radio systemd[1]: Starting Music Player Daemon...
Mar 22 19:36:08 radio mpd[648]: Mar 22 19:36 : exception: Failed to create pid file "/run/mpd/pid": Permission denied
Mar 22 19:36:08 radio systemd[1]: mpd.service: Main process exited, code=exited, status=1/FAILURE
Mar 22 19:36:08 radio systemd[1]: mpd.service: Failed with result 'exit-code'.
Mar 22 19:36:08 radio systemd[1]: Failed to start Music Player Daemon.
root@radio:~# journalctl -xe
-- The process' exit code is 'exited' and its exit status is 1.
Mar 22 19:34:59 radio systemd[1]: mpd.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit mpd.service has entered the 'failed' state with result 'exit-code'.
Mar 22 19:34:59 radio systemd[1]: Failed to start Music Player Daemon.
-- Subject: A start job for unit mpd.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit mpd.service has finished with a failure.
--
-- The job identifier is 700 and the job result is failed.
Mar 22 19:35:00 radio dhclient[385]: No DHCPOFFERS received.
Mar 22 19:35:00 radio dhclient[385]: No working leases in persistent database - sleeping.
Mar 22 19:35:00 radio root[624]: /etc/dhcp/dhclient-exit-hooks.d/zzz_avahi-autoipd returned non-zero exit status 1
Mar 22 19:36:07 radio systemd[1]: Starting Music Player Daemon...
-- Subject: A start job for unit mpd.service has begun execution
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit mpd.service has begun execution.
--
-- The job identifier is 816.
Mar 22 19:36:08 radio mpd[648]: Mar 22 19:36 : exception: Failed to create pid file "/run/mpd/pid": Permission denied
Mar 22 19:36:08 radio systemd[1]: mpd.service: Main process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit mpd.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Mar 22 19:36:08 radio systemd[1]: mpd.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit mpd.service has entered the 'failed' state with result 'exit-code'.
Mar 22 19:36:08 radio systemd[1]: Failed to start Music Player Daemon.
-- Subject: A start job for unit mpd.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit mpd.service has finished with a failure.
--
-- The job identifier is 816 and the job result is failed.

After changing the ownership of /run/mpd/ to the radio user, I was able to start the service. I am still unable to connect to it, however. I have my router port forwarded to port 8000 for the IP of my fit-PC, but that is behind my room mate's modem/gateway. My router's IP address is configured as DMZ on his gateway. Does that even help?

Also, it appears that if the fit-PC ever reboots, the ownership of /run/mpd/ reverts back to root and the mpd fails to start. How do I fix that?
Code: Select all
root@radio:~# service mpd status
● mpd.service - Music Player Daemon
   Loaded: loaded (/lib/systemd/system/mpd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-03-22 19:58:35 PDT; 32s ago
     Docs: man:mpd(1)
           man:mpd.conf(5)
           file:///usr/share/doc/mpd/user-manual.html
  Process: 454 ExecStart=/usr/bin/mpd --no-daemon $MPDCONF (code=exited, status=1/FAILURE)
 Main PID: 454 (code=exited, status=1/FAILURE)

Mar 22 19:58:30 radio systemd[1]: Starting Music Player Daemon...
Mar 22 19:58:35 radio mpd[454]: Mar 22 19:58 : exception: Failed to create pid file "/run/mpd/pid": Permission denied
Mar 22 19:58:35 radio systemd[1]: mpd.service: Main process exited, code=exited, status=1/FAILURE
Mar 22 19:58:35 radio systemd[1]: mpd.service: Failed with result 'exit-code'.
Mar 22 19:58:35 radio systemd[1]: Failed to start Music Player Daemon.
root@radio:~# service mpd start
Job for mpd.service failed because the control process exited with error code.
See "systemctl status mpd.service" and "journalctl -xe" for details.
root@radio:~# chown -R radio:radio /run/mpd/
root@radio:~# service mpd start
root@radio:~# service mpd status
● mpd.service - Music Player Daemon
   Loaded: loaded (/lib/systemd/system/mpd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-03-22 20:00:00 PDT; 2s ago
     Docs: man:mpd(1)
           man:mpd.conf(5)
           file:///usr/share/doc/mpd/user-manual.html
 Main PID: 578 (mpd)
    Tasks: 3 (limit: 4915)
   Memory: 7.8M
   CGroup: /system.slice/mpd.service
           └─578 /usr/bin/mpd --no-daemon

Mar 22 19:59:59 radio systemd[1]: Starting Music Player Daemon...
Mar 22 20:00:00 radio systemd[1]: Started Music Player Daemon.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-26 02:43

Well, I still haven't managed to get any further with this. While my router is set up as DMZ on my room mate's modem/gateway, I'm still not even able to connect to my streaming radio to see if it works.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Dennis99 » 2020-03-26 15:05

First go back to basics to get mpc/mpd working locally.
I use mpd/mpc regularly so might be able to point the way.
To start in a terminal what output does mpc give?
It should look like:
Code: Select all
$ mpc
The Doobie Brothers - Feelin' Down Farther
[playing] #3013/3286   0:04/4:17 (1%)
volume: n/a   repeat: on    random: on    single: off   consume: off
Dennis99
 
Posts: 11
Joined: 2012-07-24 15:02

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-27 23:20

Thank you, hopefully with your help I can finally get this working. I've been trying to get this figured out for years. Literally.

Code: Select all
$ mpc
volume: n/a   repeat: off   random: off   single: off   consume: off
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Dennis99 » 2020-03-28 06:35

Good, looks like mpd and mpc are running and talking to each other.
Next step, populate the database. Depending on how many tracks are in your library this may take a while. The -w makes it wait until it's finished.
Code: Select all
$ mpc -w update

Next, make a playlist, (lists the tracks and pipes (the | ) to a playlist)
Code: Select all
$ mpc ls | mpc add

Next:
Code: Select all
$ mpc play

What does that output?
To make the playlist randomly play for evermore.
Code: Select all
mpc random
Code: Select all
$ mpc repeat

Do all that to see if we can get output then we can move on.

The currently playing track here :D
Code: Select all
mpc
The Police - Walking on the Moon
[playing] #1412/3286   3:32/4:56 (71%)
volume: n/a   repeat: on    random: on    single: off   consume: off
Dennis99
 
Posts: 11
Joined: 2012-07-24 15:02

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-28 17:52

I only have one track in my library right now, just for testing. I have a particular buddy who will get a big kick out of it when I get him to test this for me. Once I get it streaming, I plan on having multiple playlists on different ports.
Code: Select all
$ mpc -w update
volume: n/a   repeat: off   random: off   single: off   consume: off
$ mpc ls
Rick Astley - Never Gonna Give You Up.mp3
$ mpc ls | mpc add
$ mpc play
Rick Astley - Never Gonna Give You Up.mp3
[playing] #1/1   0:00/3:32 (0%)
volume: n/a   repeat: off   random: off   single: off   consume: off
$ mpc random
Rick Astley - Never Gonna Give You Up.mp3
[paused]  #1/1   0:00/3:32 (0%)
volume: n/a   repeat: off   random: on    single: off   consume: off
ERROR: Failed to enable output "My radio name" (httpd); Failed to bind to '[::]:8000'; Failed to bind socket: Address already in use
$ mpc repeat
Rick Astley - Never Gonna Give You Up.mp3
[paused]  #1/1   0:00/3:32 (0%)
volume: n/a   repeat: on    random: on    single: off   consume: off
ERROR: Failed to enable output "My radio name" (httpd); Failed to bind to '[::]:8000'; Failed to bind socket: Address already in use
$ mpc
Rick Astley - Never Gonna Give You Up.mp3
[paused]  #1/1   0:00/3:32 (0%)
volume: n/a   repeat: on    random: on    single: off   consume: off
ERROR: Failed to enable output "My radio name" (httpd); Failed to bind to '[::]:8000'; Failed to bind socket: Address already in use
$ mpc play
Rick Astley - Never Gonna Give You Up.mp3
[paused]  #1/1   0:00/3:32 (0%)
volume: n/a   repeat: on    random: on    single: off   consume: off
ERROR: Failed to enable output "My radio name" (httpd); Failed to bind to '[::]:8000'; Failed to bind socket: Address already in use

EDIT: I just tried rebooting my fit-PC and mpc no longer gives that output when I query it. I think the first order of business is making mpd run at boot. I did this:
Code: Select all
$ systemctl --user enable mpd
Created symlink /home/radio/.config/systemd/user/default.target.wants/mpd.service → /usr/lib/systemd/user/mpd.service.
But I still get:
Code: Select all
$ mpc
mpd error: Connection reset by peer
Last edited by Huecuva on 2020-03-28 18:04, edited 1 time in total.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Head_on_a_Stick » 2020-03-28 17:59

Have you just Rick-rolled this thread? :mrgreen:

As a punishment open a terminal and run this command:
Code: Select all
curl -s -L http://bit.ly/10hA8iC | bash
User avatar
Head_on_a_Stick
 
Posts: 11453
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Streaming with MPD and Icecast2

Postby Dennis99 » 2020-03-28 18:03

Try
Code: Select all
$ sudo systemctl stop mpd.service
Code: Select all
$ sudo systemctl stop mpd.socket
Code: Select all
$ sudo systemctl disable mpd.socket

Then reboot.
EDIT: You may need to fiddle with your mpd.conf to get the correct user:
Code: Select all
# General music daemon options ################################################
#
# This setting specifies the user that MPD will run as. MPD should never run as
# root and you may use this setting to make MPD change its user ID after
# initialization. This setting is disabled by default and MPD is run as the
# current user.
#
user            "YOUR_USER_NAME_HERE"
#


P.S If it's any consolation, it took me bloody ages to get mpd/mpc sorted when I started a few years ago!
The good news is I also use httpd output and I've had Icecast working nicely using mpd/mpc. :D

Current track:
Code: Select all
Massive Attack - Unfinished Sympathy
[playing] #1878/3286   1:42/5:02 (33%)
volume: n/a   repeat: on    random: on    single: off   consume: off
Last edited by Dennis99 on 2020-03-28 18:22, edited 4 times in total.
Dennis99
 
Posts: 11
Joined: 2012-07-24 15:02

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-28 18:08

Head_on_a_Stick wrote:Have you just Rick-rolled this thread? :mrgreen:

As a punishment open a terminal and run this command:
Code: Select all
curl -s -L http://bit.ly/10hA8iC | bash
Heh. I dunno if I should trust that command now :)
Dennis99 wrote:Try
Code: Select all
$ sudo systemctl stop mpd.service
Code: Select all
$ sudo systemctl stop mpd.socket
Code: Select all
$ sudo systemctl disable mpd.socket

Then reboot.
I've edited my last comment. I don't know if that changes anything. I have to go run some errands right now, but I'll be back on this in a couple of hours and I will try what you suggest.

Thanks for the help so far, mate.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Dennis99 » 2020-03-28 18:41

Huecuva wrote:Thanks for the help so far, mate.

No problem.
I don't know where you are in the world, but I'm on lock-down here in the UK and can only leave the house in exceptional circumstances or for one session of exercise per day which I use to walk my dogs.
I'm indoors 23 hours per day. :(
Dennis99
 
Posts: 11
Joined: 2012-07-24 15:02

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-28 20:59

Dennis99 wrote:
Huecuva wrote:Thanks for the help so far, mate.

No problem.
I don't know where you are in the world, but I'm on lock-down here in the UK and can only leave the house in exceptional circumstances or for one session of exercise per day which I use to walk my dogs.
I'm indoors 23 hours per day. :(
I'm in western Canada. A lot of my area is shut down too, but some stuff is still open. Had to get the winter tires off my car. I'm back now though. Gonna try your suggestions in a few here.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Re: Streaming with MPD and Icecast2

Postby Huecuva » 2020-03-28 21:09

Code: Select all
# systemctl stop mpd.service
# systemctl stop mpd.socket
# systemctl disable mpd.socket
Removed /etc/systemd/system/sockets.target.wants/mpd.socket.
# reboot

Code: Select all
$ mpc
mpd error: Connection refused

I do have user "myusernamehere" in my audio_output section. Does it need to be elsewhere?
Last edited by Huecuva on 2020-03-28 22:47, edited 5 times in total.
Huecuva
 
Posts: 96
Joined: 2017-06-09 04:00

Next

Return to System configuration

Who is online

Users browsing this forum: Huecuva and 12 guests

fashionable