A simple music player that will wirelessly stream an internet music feed

Similar projects worth following
Back when I was in high school some 13-14 years ago, I used to regularly sleep to classical music playing overnight from NPR. As I have notorious sleeping problems now, I wonder if that would help

This device would need to be able to connect to a network and stream music, in its most basic form. I would like to avoid screens if possible and keep it as simple as I can, so that in sleepy incoherence I can easily smack it a couple times to get it to turn on/off. Additional configuration could be handled via ssh.

Current plan is to work with an rPi, a microswitch, and some external speakers. I might whip up an enclosure for the whole thing if I'm feeling ambitious.

See the project log below for details on installation and construction.

  • 1 × Raspberry pi I'm using a pi2, but any pi should work for this.
  • 1 × Generic microswitch Just a single push single throw switch momentary pushbutton
  • 1 × Edimax EW-7811Un Cheap USB wireless adapter

  • ​Minor code change

    Brad Arnett07/28/2016 at 07:14 0 comments

    I happened to log into the pi via ssh today, and realized that it was sucking up about 100% of a core due to the main program loop. I threw a sleep(0.02) in there to give back some of those CPU cycles should I want to do anything else on the pi, and also to shave a buck or so off my power bill.

  • Knocked it out in a night

    Brad Arnett04/30/2016 at 00:40 0 comments

    Got drunk the other night and figured, why not, now is the time for this. It turned out to be a reasonably straightforward project really. First step was going to be babbling about the microswitch, but actually, first step is my long list of assumptions!


    • You have basic linux knowledge.
    • You are running raspbian.
    • You have already set up whatever internet connection you are happy with and it gets an ip on boot.

    First... err, second step was the microswitch. I didn't want to have to look at a screen or fight with remembering commands when I was half asleep and trying to figure out how to turn this on/off at any give point in the future, so I figured a momentary pushbutton to control playback was ideal. In the interest of keeping things simple, I rummaged around for a piece of pcb with a mounting hole and got to work.

    After drilling a corresponding hole in the case for the mounting hole, I set out putting several holes in the case for the wires to feed through. I would widen these out to the size of the entire pcb with a knife later to allow for future use. As a side note, if you're working with things on a drill press, clamp them down. If they get ripped out of your hands, they're going to sting, even if it's just a lightweight raspberry pi case. About this point, I got another beer to deal with the stinging in my hand. Anyway, so there's a good mounting hole for the screw, and you have a window to the underside of the pcb. At this point I soldered the components on. ...there's no anecdote here. You start out careful and well ventilated when using a soldering iron and you don't stop. I soldered the microswitch on, wires to its contacts, and also a resistor and led that are not connected to anything as of now that I might use in the future.

    After screwing it together, I attached the wires to the pins I wanted to use and screwed the case down. The astute reader will note from the code in that I used logical pin 16 for one pin in pullup mode. I used the ground pin right next to it for the other one. You can see this in the picture, kinda. The pin you use isn't that important as long as you change to reflect which pin it's supposed to be using. Further enhancements to this (if there are any) will probably result in the pin assignment being moved into the main python module being passed into the switch module as an argument.

    So now we have a hardware button, let us consider setup. To handle the heavy lifting, I used the fantastic commandline based mpd/mpc to actually play music, and just used the python subprocess module to handle sending commands to it. You'll probably want to run "sudo apt-get install mpc mpd" while you're here (and also maybe install python3 while you're at it, because I don't remember if it's standard on Raspbian).

    Once that's done, in your home directory, you'll want to "git clone" to get the source code. You'll also want to find some music. Mpd can play music from *.mpd files, but it can't directly recognize the mpd files itself. I used the fantastic WQXR streaming channel for my music, which has an mpd file available at ( So I ran "wget" to get the pls. Inside, you'll note the URL assigned to "File1". Copy that url, and run the command "mpc add <URL>" or in my case "mpc add". Memory of this playlist should survive reboots, so we're about good here now. Connect some speakers and run "mpc play" to confirm it is working. Running "mpc stop" will stop the music again. If it works, all is well so far, if not, maybe check the url you're using, and try mine. If it's still not working, try to get a local file, mp3 or something, to work.

    So now we have a button, code, and a playlist. Lets try actually running the code and see if it works! Go into the wolfgang directory and run "python3" and press your button a few times. There's a one second delay...

    Read more »

View all 2 project logs

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates