Getting Sound Out of Flash
Nice services are flourishing all over the web to let you listen to music in intelligent ways (meaning in a way music majors don’t like). To name a few: Pandora, Last.fm, Deezer or Seeqpod. There are much more but these are my favorites at the moment.
Now there’s a notorious problem with playing music through the Flash plugin of your browser: it’s a tightly closed black box. There’s an attempt at creating open source versions of the Flash player but it’s not quite there yet (although it works well for YouTube and I dearly hope it will improve). For me this closed environment is a problem: first I don’t like closed software, second I can’t listen to that music later or offline and third I can’t send it to my airport express, which deeply annoys me.
But this time, my friend, is over. Come PulseAudio. It’s an open source sound server allowing for pluggable music producers and consumers. So you can read music on your computer and have it played on another machine on the network. Or control the volume for each source individually. Or do all kind of other smart tricks. And it runs either on Windows or Linux (sorry Mac users, you can’t have both reflection in Dock and good open source software).
Turns out that you can have the Firefox flash plugin send what it’s playing to PulseAudio. And configure PulseAudio to have this stream written to a sink file on your filesystem. And read the stream from that special file to write it to a regular file. Or send it over to your Airport Express. Or do whatever you want with it. Freedom, finally.
So here is a short How To to get this working on Linux (sorry Windows users, you won’t get past step 2 even if you don’t have Dock reflection):
- Install PulseAudio. I hear it’s already in Fedora 8. For (K)Ubuntu users, there’s a decent tutorial from the Debian guys.
- Compile and install the Flash player library for PulseAudio. There’s a nice little guide. Although on Ubuntu the latest available version of libpulse is 0.9.6 and the one required to compile is 0.9.7. So I just changed the version in configure.ac and it did the trick.
- Edit /etc/pulse/default.pa and uncomment the line: load-module module-pipe-sink
- Restart Firefox if it was already started and start playing music. You can open pavucontrol to see what is playing and redirect it to the file sink (right click on the source).
- To verify that something get played just cat /tmp/music.output and try to read the matrix.
From there you can do a lot of things. Write the sink to a classic file that you can keep around with a cat /tmp/music.output > myfile for example. Note that this is raw music but you can probably send it to lame to encode to mp3. Personally, I pipe the file sink to an Airport Express using raop-ruby.
Music sounds so sweet to my ears.
Picture from tonifrancois.
Matthieu Riou on December 4th 2007 in Uncategorized
Labnotes » Rounded Corners - 170 (For certain values of normal) responded on 06 Dec 2007 at 12:34 pm #
[...] out. Matthieu has a recipe for streaming audio from Flash (Pandora, Deezer) to the otherwise not that useful Airport Express. That is, if you’re [...]
Getting Sound Out of Flash-legal mp3 music downloads responded on 02 Jan 2008 at 11:35 am #
[...] unknown wrote an interesting post today onHere’s a quick excerptNow there’sa notorious problem with playing music through the Flash plugin of your browser: it’sa tightly closed black box. There’s an attempt at creating open source versions of the Flash player but it’s not quite there yet (although … [...]
interim_descriptor responded on 01 Feb 2009 at 11:51 am #
To expand on this, you may encode with lame as so:
cat music.output | lame -r -b 320 -s 44.1 – - > music.output.mp3
…but music.output seems to send gaps of silence to lame… Hmm…
Using pulseaudio 0.9.10