You are on page 1of 9

PiMusicBox

Whatisit?
Soyouhavethishugelibraryof20+millionsongsonSpotify,justwaitingforyoutoplaythemon
yourcomputer.Spotifyisgreat.Buthowtoplaythesesongsonyouraudioset?Usinga
headphonecable?Hmmm.Notgreatwithyournotebook.Bluetooth?Hmmm.Unreliable.
EnterPiMusicBox.ItturnsyouPiintoamusicplayer,supportingSpotify,GoogleMusic,
SoundCloud,AppleAirplayandWebRadio.Amusicplayerwhichyoucanoperatefromyour
couchusingatablet,smartphone,notebookordesktopcomputer.ConnectyourRaspberryPito
anaudioset,installthesoftwareandwelcometoanewwayoflisteningtomusic!
Requirements
Forthishack,youllnotonlyneedaworkingPi,butalsoaSpotifyPremiumaccountandanaudio
set,headphonesorasetof(USB)speakers.Amonitorortelevisionisnotrequired,butmight
comeinhandy.
GettingtheSoftware
Downloadthereadytoeatimagefromwww.pimusicbox.com.Itjustworks,youonlyhaveto
editsomeoptions.Forthisguide,weusedPiMusicBoxversion0.4.Newversionsshould
generallyworkaboutthesame,thoughoptionscouldchange.
InstallingPiMusicBox
Extractthezipfile.PuttheresultingimageonyourSDCardbyfollowingtheseinstructions.The
imageistestedona1GBSDcard,butyoucanputitonalargerone.
Possibilities
PiMusicBoxisdesignedtobeoperatednotfromthePiitself,butfromanothercomputerlikea
notebook,desktop,tabletorsmartphone.Youcanusealmostanydevicewithamodernweb
browsertooperateit(Chrome14+,Safari6+,Firefox11+,InternetExplorer10+).
ItcanoutputthesoundnotonlytotheheadphonesjackofthePi,butalsothroughHDMIand
USB.ItsupportsWifi,LastFM,anditcanplayyourownmusicfilesfromtheSDCardorthe
network.Thesoftwarewilldetectasmuchoftheconfigurationaspossibleatboot,andconfigure
thesystemautomatically.Butyouhavetosupplythesystemwithsomeinformation.
ConfiguringyourBox
Tomakeitaseasyaspossibletoconfigure,youcaneditthesettingsofPiMusicBoxwithout
everloggingintoLinux.Todothis,puttheSDCardintoacomputer(Windows,Mac,Linux),and
openthecontentsofthecardinthefilemanager.
Aspecialfoldercalledconfigshouldbethere.Initisafilecalledsettings.ini.All
configurationisdonehere,sostartupyourfavoritetexteditor!

Thefileisstructuredasaninifile.Alllinesstartingwitha#arecomments.Readthecomments,
orjustignorethem.Someconfigurationlinesarealsocommentedout.Ifyouwanttousethem,
removethe#atthebeginningoftheline.
YoucanbythewayalsoeditthisfilewhenyoubootyourPiandyoulogin(seeGettingyour
HandsDirty).Thefilethenislocatedin/boot/config/.
BasicConfiguration
Themostbasicconfigurationfilelookslikethis:
[MusicBox]
SPOTIFY_USERNAME=spotifyusername
SPOTIFY_PASSWORD=spotifypassword
[MusicBox]isthesectionoftheconfigurationfile.Ithastobethere,butyoucanignoreit.
spotifyusernameisyourtheusername(orFacebookloginifyouuseFacebooktoconnectto
Spotify)ofyourSpotifyPremiumaccountandspotifypasswordisofcourseyourownpassword.
ThisshouldbeenoughtorunPiMusicBox.
Networking
PiMusicBoxneedsanetworkconnectiontooperate.Ifyouuseawirednetwork,youonlyhaveto
pluginthenetworkcableinthePi.ItwillbeconfiguredusingDHCP.Ifyouwanttouseastatic
address,youneedtogetintotheconsoleandconfigureityourself(seeGettingyourhands
dirty).ConnectingthroughWifiusingadongleisalsosupported(moreinformationonthat
below).
Booting
Afteryoueditedthebasicsettings,youcanbootPiMusicBox.Youcaneditalotmoresettings,
butitsgoodtotrybootingwiththebasiconesfirst.PuttheSDCardinthePi,connectspeakers
andconnectthepower.IfyouconnectamonitortotheHDMIconnector,youcanfollowthe
bootingprocess.Afteraminuteorso,youcanaccessthesystem.
AccessingtheWebInterface
PointyourbrowsertothePi.Dependingonyournetworkandcomputers,itwillbeavailableat
thisaddress:
http://musicbox.local/
MostOSX/iOSandWindowsdevicesprobablywillfinditimmediately.Ifitdoesn'twork,you
couldtrytoinstallAppleBonjour/iTunesinWindowstomakeitwork.Linuxshouldalsoworkif
AvahiorSamba/Winbindisinstalled.Youhavetoaddthehttp://partoftheaddressinsome
browsers,becauseotherwise,itwilltrytosearchformusicbox.localinGoogle.

Ifitdoesntwork,orifyouuseAndroid(whichdoesnotsupportBonjour/Avahi/Samba),youhave
toaccessMusicBoxusingtheIPaddressofyourPi.Thisaddressisdifferentoneverynetwork,
e.g.http://192.168.1.5/orhttp://10.1.100.2.Youhavetoeitherlookitupusinganetworkutility,or
(easier)readitfromthescreenwhenPiMusicBoxboots.
PlaysongsfromSpotify
Ifyouaccesstheinterface,mostthingsareclearimmediately.YourSpotifyplaylistswillappear.
Selectoneoftheplayliststoshowthetracksitcontains.Selectthetrackyouwanttoplayand
chooseoneoftheplayoptionsinthepopupmenuthatappears.Usingthispopupmenu,youcan
eitherplaythesong,addittothequeue,orfindmoretracksfromthesamealbumorthesame
artist.Justplayaround.Literally.
Thefourbuttonsatthebottomofthescreen,letyouaccessthefunctionsofMusicBox.Youcan
accesstheplayingQueue,searchfortracks,albumsandartists,orplaywebradiostations.
WebRadio
Toplaystreamsfromradiostationsyoulike,youhavetouseasocalledstreamurl.Youcannot
usecontainerfileslikeM3U,XSPForPLS(yet),whicharecommonlyavailable,youhavetoadd
therealstream.Thisstreamurlishiddeninsidethe.M3UorPLSfile.Tofindthisurl,openthe
containerfileinatexteditor.
APLSfilelookslikethis:
[playlist]
numberofentries=1
File1=http://vprbbc.streamguys.net:8000/vprbbc24.mp3
Title1=BBCWorldService
Length1=1
version=2
Thestreamurlwouldbe:
http://vprbbc.streamguys.net:8000/vprbbc24.mp3
M3UandXSPFfileslookdifferent,butthestreamurlisalwaysclearlyvisible.
Youcanfindradiostations(PLSandM3U)usingserviceslikehttp://dir.xiph.org/or
Listenlive.euorDirble.com.
JustaddthestreamurlandthenameofthestationandpressthePlaybutton.Thelast25
stationsaresavedlocallyusingabrowsercookie(notontheserveryet,soyouneedtodoiton
everyclientyouuse).
MPD
Thoughthewebbasedinterfaceisrecommended,youcanalsousenativesoftwarewhich
supporttheMPD(MusicPlayerDaemon)protocoltocontrolPiMusicBox.

Appsandapplicationsareavailableforallsortsofdevicesandoperatingsystems.Notallof
themworkgreatwithMusicBoxthough.ForAndroid,MPDroidisrecommended.OnOSX,
Thereminworks(withoutsearch).OnLinux,youcanusethegreatworkingandwonderfully
namedconsoleappncmpcpp.OnaLinuxDesktop,GMPCandSonataworkwell.OniOS,
mPodandmPad.ForWindows,clientsareeithernotworkinggreatoruntested.
Moresettings
AlotofthingscanbeconfiguredonMusicBox.Edittheconfigurationfileaccordingtoyour
needs.YouhavetoreboottheBoxtoseethechanges.
WifiNetwork
IfyouconnectasupportedwifidongletoyourPi,theMusicBoxsoftwareshouldbeabletodetect
anduseitinsteadofacableconnection.Mostdonglesaresupported,butnotall.Ifyoubuyone,
makesureitssupportedbyRaspbian,theLinuxdistributiononwhichMusicBoxisbased.
Tomakewifiwork,youhavetofillinthenetworkname(SSID)andyourpasswordintheconfig
file.Addtheselinestothebasicconfigurationabove,oreditthedefaultfilesuppliedwith
MusicBox.
WIFI_NETWORK='mywifinetwork'
WIFI_PASSWORD='mypassword'
Substitutethemywifinetworkandmypasswordwiththecorrectvaluesofyourownnetwork.For
now,thewifionPiMusicBoxonlysupportsWPA(2)encryptednetworks,configuredviaDHCP.
Aswithawirednetwork,ifyouwanttouseastaticaddress,WEPencryptionornoencryption,
youneedtogetintotheconsoleandconfigureityourself(seeGettingyourhandsdirty).
BetterQuality
ThePicanplaythemusicfromSpotifyindifferenttypesofquality.Thebetterthequality,the
moredataneedstobedownloadedfromSpotify.Itscalledbitrate.Higherqualitymeansahigher
bitrateandabitmoreuseofyourinternetconnection.Typicalbroadbandconnectionsshouldbe
abletosupportthehighestbitrateeasily.Ifyouhaveagoodconnectiontotheinternet,youcan
setthequalitytohigh,butifyourconnectionissloworunstable,oryouhaveusagelimitsonyour
connection,youcanitloweranduselessdata.Possibleratesare96(low,butacceptable
quality,FMlike),160(default)or320(highestquality,CDlike).
Setthebitratetohighlikethisintheconfigurationfile:
SPOTIFY_BITRATE=320
Orsetthebitratetolowlikethis:
SPOTIFY_BITRATE=96
SoundConfiguration
BydefaultPiMusicBoxwillsendthesoundtotheanalogheadphoneoutputonthePi.Thissound
isgoodenough,butduetohardwareconstraints,notalwaysgreat.Ifyouwanttohavebetter
sound,usetheHDMItoconnectthePitoanamplifier,orconnectanUSBsoundcard(also

calledUSBDAC,DigitalAudioConverter),USBspeakersorUSBheadphones.Almostalltypes
ofUSBspeakers,headphonesandDACsaresupported,butifyoubuyone,makesureitsLinux
compatible.DACswithdigitaloutputsarealsoavailableinmanywebstores.
Whenbooting,PiMusicBoxwillautodetectwhatisconnectedtothedeviceandconfigureit
accordingly.Ifyouconnectmultipledevices,USBwillbeselectedfirstasasoundoutput,HDMI
afterthat,andlastlytheanalogoutputofthePiitself.Youcanoverridethisinthe
configurationfileusingthefollowingline:
OUTPUT='analog'
Ifyouincludethis,thedefaultoutputwillbetheanalogheadphonesjackofthePi,evenifyou
connectedanUSBdeviceoranHDMIcable.
Theoptionsare:'analog','hdmi','usb'
LastFM
AnotherservicesupportedbyPiMusicBoxisLastFM.Itcollectsthetracksyouplay,soyoucan
discovernewmusic.Gotowww.last.fmtocreateanaccountifyoudontalreadyhaveone.To
letLastFMcollectthetracksyouplay,fillinthecredentialsofthisservice.
LASTFM_USERNAME='lastfmuser'
LASTFM_PASSWORD='lastfmpassword'
SoundCloud
PiMusicBoxhasrudimentarysupportforSoundCloud,theservicewhichletsyouHearthe
worldssounds.Toconfigureit,youneedaspecialID,atoken.Getthistokenfrom
http://www.mopidy.com/authenticateYouhavetologinwithyourSoundCloudidtogetthetoken.
Thisinformationisnotsharedwiththemopidy.comsite.Whenyoulogin,youllseeatoken
appearonthepage.Addthistokentotheinifilelikethis:
SOUNDCLOUD_TOKEN='11111111111'
SOUNDCLOUD_EXPLORE='electronic/Ambient,pop/NewWave,rock/Indie'
Whereyoureplacetheexample1111111111byyourtoken.Usingthe
SOUNDCLOUD_EXPLOREconfiguration,youcanconfiguretheplaylistsyouwanttoseeinthe
interface.
MultiRoomAudio
PiMusicBoxsupportssocalledMultiRoomAudio.YoucanhavemultipleRaspberrysonyour
network,forexampleindifferentrooms.Thedevicesneedtohavetheirownnamestobe
accessible.UsethisoptiontogiveyourMusicBoxadifferentname:
NAME=`Kitchen

Thenameyouchooseshouldbenolongerthan9charactersandonlycontainnormal
charactersandnumbersinthename(nospaces,dots,etc).
Afteranewboot,thewebinterfaceforplayingmusicwillbeaccessibleviaanewaddress.
Wherethedefaultwouldbehttp://musicbox.localfromdevicesthatsupportBojour/Avahi,when
youchangethename,itbecomeshttp://newname.local.Intheexampleaboveitwouldbe
http://kitchen.local/
ItsnotpossibletoplaydifferentmusiconmultipledevicesusingthesameSpotifyaccountatthe
sametime.ThisisalimitationofSpotify.Ifyouhavemultipleaccounts,itofcourseispossible.
Security
PiMusicBoxisnottotallysecureandnotintendedtorunoutsideafirewall,onlyinthecosy
environmentofyourlocalnetwork.TheheartofMusicBox,isnotprotectedenoughtodothat.
Also,thepasswordsofSpotifyandwifiarestoredinplaintextontheSDCard.Thismightbe
fixedinthefuture.
Formoresecurity,changethedefaultpasswordbysettingthisline:
MUSICBOX_PASSWORD=mypass
wheremypassisyournewpassword.Thiswillchangethepasswordsofboththeuser
musicboxandtheuserroot.Thepasswordwillberemovedfromtheconfigurationfileafterits
updated.
Ifyouwant,formoresecuritytochangetherootpasswordtosomethingelse,usethisline:
ROOT_PASSWORD=mypass
wheremypassagainisyournewpassword.
PlayingyourownMusicFiles
ThoughSpotifyboastsalibraryofover20milliontracks,notallartistsandsongsare
represented.SoitwouldbenicetobeabletoplayMP3filesforthemissingsongs,wouldntit?
WellthegoodnewsisthatPiMusicBoxsupportsplayinglocalornetworkedMP3,FLACorOGG
files.Thebadnewsisthatitsatinybitcomplicatedinthecurrentversion(0.4).Also,thesongs
arenoteasilyavailableinthewebinterface.Theyarenotintheplaylists,youhavetosearchfor
themtoplaythem.
NetworkedMusic
Theeasiestwaytoplayyourownmusicfiles,isviatheWindowsNetwork.Todothat,editthe
configurationfile,sothatMusicBoxknowswhereyourfilesare.Thisaddresscouldbeabit
cryptictoafirsttimeuser.Thisisanexample:
NETWORK_MOUNT_ADDRESS='//192.168.1.5/musicshare'
or:

NETWORK_MOUNT_ADDRESS='//mynasserver/shared/music'
Thefirstpart//isthewaysharesintheWindowsNetworkarecreated.Justadditandforgetit.
Thenextpart(mynasserveror192.168.1.5)isthenameoripaddressoftheserverwhichhosts
thefile,andthelastpart/musicshareor/shared/music,tellsMusicBoxwhichsharetomount.
Whenyourserverisprotected,youneedtosettheusernameandpasswordfortheNetwork
shareusingthefollowingconfigurationlines:
NETWORK_MOUNT_USER='username'
NETWORK_MOUNT_PASSWORD='password'
ScanMusic
MusicBoxwillnotseethefilesimmediately.Themusicfilesneedstobescannedatboot,every
timeyouaddorremovefiles.ThisprocesscanslowdownthebootoftheMusicBox,souseit
withcare.MusicBoxwillscanthefilesusingthefollowingconfigurationlines:
SCAN_ONCE='true'
or
SCAN_ALWAYS='true'
Thenamesspeakforthemselves.UsingSCAN_ONCE,themusicfileswillonlybescanned,
yes,once.Usethisifyoudontchangethemusicfilesoften.UseSCAN_ALWAYSifyouchange
yourmusicfilesalot.ThiswillenableyoutochangethefilesandrebootMusicBox.Itwill
recognizethenewfilesaftertheboot.But,again,thescanningprocesscanslowdownthe
bootingofMusicBoxconsiderably.
LocalMusic
PiMusicBoxalsohasanoptiontostoremusicfilesontheSDCard.Thisprocessisalsoabit
morecomplicated.SinceMusicBoxiscreatedfora1GBSDCard,orlarger,thefilesystemis
alsolessthan1GB.IfyouputMusicBoxonalargerSDCard,therestofthespaceonthecard
wontbeused,unlessyouresizethefilesystem.
Youcandothismanually,onacomputerusingapartitionmanager,oryoucanletMusicBoxtry
toresizeitautomatically.Thisprocessistested,butnotguaranteedtowork.Youcouldendup
withanonworkingmusicboxiftheprocessfails.Thatsmostofthetimenoproblem,sinceyou
canputtheoriginalMusicBoximageontheSDCardagainandstartover.Ifyoudidalotof
customization,itsrecommendedtobackupyourcardfirst.
Usingthislineinthesettings,PiMusicBoxwillautomaticallyresizethefilesystemtothe
maximumsizeoftheSDCard:
RESIZE_ONCE='true'
PutFilesontheCard
PuttingmusicfilesontheSDCardisonlyrecommendedoncardswithasizelargerthan1GB.
MusicBoxneedsthe1GBforcachingandotherstorage.AfterresizinganSDcardwithmore
storage,youcanputyourownmusicfilesonthePiusingeithertheWindowsNetwork,orby

mountingtherootfilesystemofthecardonaLinuxcomputerandcopyingthefiles.Leaveat
least200MBoffreespaceonthedevice.
TousetheWindowsNetwork,youhavetohavetheworkgroupnameoftheWindowsNetwork
settothedefaultname,WORKGROUP.Ifyouwantanothername,youhavetochangeitby
handinthefile/etc/samba/smb.conf(seeGettingYourHandsDirty).
RemembertoletMusicBoxscanthefilesatboot(seeScanMusic)
GettingYourHandsDirty
Ifyouarewillingtogetyourhandsdirty,therearealotmoreoptionstoexploreinPiMusicBox.
Forthis,youhavetologintotheboxontheconsole,orviaSSH.
TologinremotelyviaSSH,youwillneedtoenabletheSSHservice.Dothatbyaddingthislineto
yourconfigurationfile:
SSH_ENABLED=true
Reboot.Afterthat,youcanconnecttoMusicBoxviaSSH.
Mopidy
ThemainingredientofMusicBoxisMopidy,anopensourcemusicserverdevelopedbypeople
fromallovertheworld.Itcanbeextendedinanumberofways.Bydefault,PiMusicBoxissetup
usingthebestworkingextensions.Butitcanbeextendedtoplaymusicfrome.g.SoundCloud,
GoogleMusicandBeetsMusic.Moreextensionsaredevelopedasyouread.
Howtoaddtheseextensionsisbeyondthescopeofthisdocument,butalotofresourcesand
documentationcanbefoundonwww.mopidy,comThedeveloperscanbereachedonthemail
listofMopidy,https://groups.google.com/forum/?fromgroups=#!forum/mopidy,orviaIRCChat
onthe#mopidychannelonFreenode.
rc.local
AnotherimportantpieceofPiMusicBoxisthefile/etc/rc.local.Itsashellscript.Thisiswhere
the(sound)hardwareissetupandtheconfigurationisdone.Forexample,theconfigurationfile
ofMopidyiscreatedfromrc.local.Editthisfileisyouwanttoadd,changeorremovefeatures.
WorkingatMidnight
ForLinuxnovices,aniceutilitycalledMidnightCommandercouldbeofusetobrowsethe
filesystemandeditfiles.ItworksliketheageoldDOSutilityNortonCommanderanditsincluded
inMusicBox.Startitusingthecommand:mc
StaticNetwork
TouseMusicBoxinanetworkwithstaticIPaddresses,youhavetoeditthefile
/etc/network/interfaces.
Thelinesthatconfigurethewirednetwork,looklikethis:

allowhotplugeth0
ifaceeth0inetdhcp
Anexamplefileforastaticwirednetwork,youshouldchangeittosomethinglikethis:
ifaceeth0inetstatic
address192.168.1.5
netmask255.255.255.0
gateway192.168.1.1
Fillinthecorrectipaddressesforyournetwork.
Development
Ifyouwanttoeditfilesofe.g.thewebclientfromanothercomputer,youcansharethefolder
containingthefilesintheWindowsNetwork.Forthat,editthefile/etc/samba/smb.confandadd
this:
[Webclient]
path=/opt/webclient
writable=yes
browseable=yes
guestok=yes
createmask=0755
directorymask=0755
Next,issuethiscommand(whichenableswriteaccesstothefiles):
chownRmusicbox:musicbox/opt/webclient
Updating
WhenanewversionofMusicBoxisreleased,theonlywaytoupdateit,istodoanew
installation.Youcanupdatethekernelandotherpackagesofthesystemmanually,butchanges
inthefilesspecificforMusicBoxwillnotbeupdated,soitcouldeventuallybreakthings.
Generallyitsnotneededtoupdatethings,butifyoureallywant,youcouldissuethecommand:
rpiupdatetogetthelatestkernel.Thiswilltakeawhile.Anothercommandisaptget
update&&aptgetdistupgrade.Thesecommandstakeawhiletorun,sograba
coffee!
Fun&Questions
Enjoyyournewwayoflisteningtomusic!Ifyouhavequestions,dontbeafraidtoaskthemat
ThemailinglistofMopidy/MusicBox,orviachat.Addressesandinstructionsareon
www.pimusicbox.com

You might also like