Tuesday, January 29th, 2008
Stream Your Music Library from a Computer to your iPhone
This will be a total geek post, so beware. Tonight I made my own streaming music server, which basically lets me listen to any of the music living on my home computer through my iPhone. So in other words, I should be able to plug my iPhone into the cars stereo and play any song that is on my computer back at home, from anywhere.
There are several reasons youd want to do something like this, the main one being that you no longer need to store the music on your iPhones hard drive. This means that youd have more room for other stuff on your phone, and you also wouldnt have to constantly think did I put that song on my iPhone?
I better put in a quick disclaimer about my limited success with this project. While I was able to make this all work, there are some details that I cannot work around that will prevent this from being a huge oh wow! solution. Those details can be found at the bottom of this post under the title Why It Isnt That Awesome.
Listening to my music isnt necessarily something you want to do, although technically you can access it right now from your browser. You just have to know the URL where I keep all the music, but you probably wont figure that out. So lets assume youre still reading this, which means that you are probably interested in setting up your own music server. Awesome, youre a geek. Congratulations.
There are several steps involved in getting this whole thing up and running, but heres the gist of it:
Home Server
You need to have a computer in your home that functions as a server. This computer will need to be on all the time, and it will most likely be the computer that stores all of your music. I had one of these already in place, so yeah for me.
Local or Global?
If you want to listen to your music from outside your home, you will need to configure your home server to be available outside of your local network. This involves a lot of technical stuff that is brimming with security risks, so make sure you know what youre doing.
Granting Server Access to your Music
Your server will probably not be able to access your music directory right off the bat. If you have an Apache server for example, you will need to open the config file and add an alias line that will point a specific URL to any directory on your system. This was my biggest roadblock, because on the computer that I use as a server, my web stuff is on one hard drive, and all my music lives on a separate drive in that same computer. It took way longer than it should of to figure out I had to change the Apache config file in order to hook it all up.
Server-Side Programming
Your server needs to have some sort of language installed that will enable you to write some code that lists the available files and folders in your music directory. My entire music program is about 200 lines of PHP code, all contained in one file.
That sums up the overall process, but of course each one of those steps has a steep learning curve if youre not familiar with the process. In my case, I had a PHP-enabled web-accessible server already that stored all my music, so that was nice.
How It Works
Music is shared through a web browser. So open a browser, and go to my sample music page I set up on this server just to show you what its like. On this example, my A folder is the only one with music, so go there. The code will list all folders in there, which are all artist names, and when clicked, will present you with a list of songs inside that folder. If there are sub-folders that contain tracks from an album, those tracks are grouped together and listed under that albums name. Clicking on a song name will load the MP3 directly in your browser, which should start playing the song.
Why It Isnt That Awesome
Loading an audio file into your browser will take over the browser in a sense, presenting you with the song file, nothing else. This prevents me from adding any sort of code that will be processed when the song is over, making it impossible to link multiple songs together. When a song is done, you have to manually hit the back button and choose your next song. This is a real bummer, and this will be the biggest reason I dont stream more music using this system.
But...
As much of a bummer as the previous point was, this system still has its place. There have been numerous times where Ive wanted to hear that song — you know, the one that just popped into your head randomly — but I dont have it loaded on my iPhone. If Im away from home, I have no options. With this system, it will let me do two things. One of those things is listen to the song through a web browser (on a computer or the iPhone). The other thing is that through a browser, I can download the file to a computer. This will come in handy quite often, cause many times at work I want to listen to music that I know I have at home, but I never remember to bring it with me the next day. It might be a little inefficient to have to manually click and download each track in an album, but it works.
Try It Out Yourself
In case you didnt catch it above, I have a sample music server set up on this website. This will let you see what its like, and you can also listen to a very small selection of my music. Click Here and then go to the A folder (all the others are empty). I wont have these online long though, just for a bit so you can see what its like. ![]()
RELATED TOPICS: computer geek stuff, music
I did this a few years ago and it worked pretty well. Of course this was before the iPhone and actually before the iPod even so I guess it was more than a few years ago, back before servers and car stereos were invented. I used it to listen to my music at work from home too.
Its not ideal to manage really but you can create an m3u playlist from songs on the server. The m3u file is nothing more than a simple XML file with references back to the song/path on the server. I think it can also store the song title, artists, etc which you can pull from the ID3 tags in the header of the song file (I have seen this done with PHP too). Its gonna definitely add a few more lines to your nice little 200-line script but in theory you could probably make it dynamically build playlists that way.
I am currently listening to Keep the Car Running (Arcade Fire) on your server and its working flawlessly. Nice work Dave! If you could go ahead and upload your entire music catalog that would be um.... GREAAAATTT.
1
Thanks for the tip Denny. Ive played around with m3us for a bit this morning, but there doesnt seem to be a way to get them to play in browsers (at least Safari, either on the computer or the iPhone). You can see my test page at:
http://www.daveheinzel.com/m3u/
The file thats linked to on that page is a valid m3u file that will open with iTunes when I click it. Also I can download it and open it with QuickTime just fine, but for some reason it wont play within the browser. Ive played around with the .htaccess file and MIME types, but nothing doing so far.
I like the idea though, cause if it worked, I could use session info to build playlists or let someone listen to a whole album at once (or do a shuffle). Its so close to being able to work.
2
Im really bummed that Google hasnt made any improvements to their telekinesis program for the iPhone. It would let you browse music from a server as well as any other files that the iPhone would open. I also loved that you could access an iSight camera and take screen captures.
http://code.google.com/p/telekinesis/
Joe
TUESDAY, JANUARY 29TH, 2008 8:45 AM3
Could you do something like (hack? yes, but itll work..):
Present the iphone with a page listing all of the songs in the album with checkboxes. Select the ones you want and on the server you build a temporary mp3 file by concatenating the requested mp3s into a single file and stream that back to the browser? The mp3 format will allow such a thing and will play fine.
Youll need to write something to go and cleanup those temp files every now and again.
Anyway, just a thought.
EJ
TUESDAY, JANUARY 29TH, 2008 10:54 AM4
Not a bad idea, but its a bit of a load on the server, and it might take it awhile to generate the finished MP3.
I am just totally bummed that m3us wont play in Safari on the iPhone, cause that would be very easy to do. Im going to leave it as-is for now, and possibly when Apple comes out with their SDK next month, there will be a solution in there somewhere that will make this system more attractive.
Another thing that would suffice is to embed the MP3 into a web page (using <embed> tags), but Safari on the iPhone ignores embedded music, so thats a no-go.
It would be nice for the iPhone to enable you to listen to any shared iTunes libraries on your network. True, this would limit its reach to your local network, but that would be step in the right direction.
5
For a small (< 10) number of users, I dont think itll be as large of a load on the server as youre thinking. Its obviously a horrible idea for dozens of users, but if youre just wanting something to get you by... It would be easy to test out.


