~hristoast/hristoast

hristoast/site/mpd-through-a-bluetooth-speaker.html -rw-r--r-- 4.2 KiB
fe7dc4e8Hristos N. Triantafillou More comments, and some cleanup a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<h1 id="title">MPD through a bluetooth speaker</h1>

<div id="dates">
  <span>Posted: <time id="post-date">2017-02-25</time> | Updated: <time>2020-12-10</time>, <time>2021-01-04</time></span>
</div>

<p>
  <span class="bold">UPDATE!</span> Check out <a href="/blog/listening-to-music-on-linux-with-mpd-part-4/">my latest post on MPD</a> to see an updated writeup on my MPD setup and usage.
</p>

<p>
  It's also worth mentioning that since I published this and the updated entry, I've stopped using a Bluetooth speaker with MPD. There were just too many issues with reliability and "lag" that I now connect my bluetooth speaker with an audio cable. A fair warning for those that want to go down this path.
</p>

<p id="post-excerpt">
  I recently grabbed a bluetooth speaker, intending to mostly use it with my phone, but I quickly found myself wanting to play my laptop's MPD through it. Today I'll describe how I got it going - and In the process we'll also resolve some issues with the setup described in <a href="/mpd-local-listening/">my other MPD post</a>.  The process was pretty straight forward but it didn't just work so I figured I would talk about it a bit here.
</p>

<div id="toc"></div>

<h3>The speakers</h3>

<p>
  I'm really not sure how much this varies from speaker to speaker, but I imagine not much.  At any rate nothing special had to be done with the speaker;  Just switch it on and connect it to your machine (I use <code>blueman-applet</code>, personally.)  Aside from this I don't have anything particular to say about the speakers (and I don't think it's important to mention the brand I have.)
</p>

<h3>The config</h3>

<p>
  Now you've got speakers that are connected, but no sound comes out (from MPD.) You'll likely need to tweak MPD and Pulseaudio (assuming you are using the latter...) to remedy this situation. 
</p>

<h3>MPD</h3>

<p>
  This is the easy part; we just need to make sure that MPD connects to a Pulseaudio stream on <code>localhost</code>.  The explanation is not so simple, and is best explained <a href="http://askubuntu.com/a/555484">here</a>, but the short version is that since Pulseaudio is running in a user (not system) session, our system MPD needs to talk to Pulse this way.  Add this to your <code>audio_output</code> block:
</p>

<pre><code>server	"localhost"
</code></pre>

<p>
  Then, restart MPD.
</p>

<h3>Pulseaudio</h3>

<p>
  You are using Pulseaudio, right?  It's OK if not but I'm afraid the following won't apply to you.  To ensure that your user session of Pulseaudio can be reached by MPD an ACL rule needs to be added for TCP communication on <code>localhost</code>.  One can do that with this command:
</p>

<pre><code># Run this as your unprivileged login user
$ pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
</code></pre>

<p>
  Or, this can be set globally in the <code>/etc/pulse/default.pa</code> file.
</p>

<h3>On MPD and Pulseaudio...</h3>

<p>
  I had <a href="/mpd-local-listening/">previously</a> talked about setting up MPD for use as one's primary music player.  One relatively major caveat which I did not mention in that post was how, when set up as I described, MPD would not utilize Pulseaudio as it was intended; it would instead try to work as if the connection was ALSA.
</p>

<p>
  What this means is that MPD, when running, would not be just another audio stream handled by Pulseaudio.  Not only that, but it would actively clobber or be clobbered by other "real" Pulseaudio streams.  This manifests itself in the form of other audio not working while MPD is running, or MPD not running while other audio is running.  Definitely annoying but somewhat manageable...
</p>

<p>
  But now.. with the above tweaks to Pulseaudio and MPD, it now acts like a normal Pulseaudio stream!  This means it can play alongside other audio streams and will generally behave just like you expect it to.  Pretty awesome!
</p>

<h3>Conclusion</h3>

<p>
  So there you have it - we've not only hooked up MPD to some bluetooth speakers but we also solved a nagging configuration issue with it! Nothing too terribly crazy but it didn't work out of the box and did take a bit of searching to arrive at the (somewhat obscure for non-Pulseaudio experts) solution.  Cheers to not using a GUI music player!
</p>