RECENT BLOGS

Stream Your Music Library from a Computer to your iPhone


ARCHIVE

2004  2005  2006  2007  2008  


Humzoo - share your life

I Support Barack Obama



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 car’s stereo and play any song that is on my computer back at home, from anywhere.

There are several reasons you’d want to do something like this, the main one being that you no longer need to store the music on your iPhone’s hard drive. This means that you’d have more room for other stuff on your phone, and you also wouldn’t 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 Isn’t That Awesome.’

Listening to my music isn’t 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 won’t figure that out. So let’s assume you’re still reading this, which means that you are probably interested in setting up your own music server. Awesome, you’re a geek. Congratulations.

There are several steps involved in getting this whole thing up and running, but here’s 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 you’re 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 you’re 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 it’s 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 album’s name. Clicking on a song name will load the MP3 directly in your browser, which should start playing the song.

Why It Isn’t 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 don’t 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 I’ve wanted to hear “that song” — you know, the one that just popped into your head randomly — but I don’t have it loaded on my iPhone. If I’m 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 didn’t catch it above, I have a sample music server set up on this website. This will let you see what it’s 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 won’t have these online long though, just for a bit so you can see what it’s like.

RELATED TOPICS: computer geek stuffmusic

COMMENTS

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.

dennydeaton     TUESDAY, JANUARY 29TH, 2008 7:58 AM

1


Thanks for the tip Denny. I’ve played around with m3u’s for a bit this morning, but there doesn’t 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 that’s 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 won’t play within the browser. I’ve 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). It’s so close to being able to work.

daveheinzel     TUESDAY, JANUARY 29TH, 2008 8:34 AM

2


I’m really bummed that Google hasn’t 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 AM

3


Could you do something like (hack? yes, but it’ll 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.

You’ll 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 AM

4


Not a bad idea, but it’s 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 m3u’s won’t play in Safari on the iPhone, ‘cause that would be very easy to do. I’m 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 that’s 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.

daveheinzel     TUESDAY, JANUARY 29TH, 2008 11:22 AM

5


For a small (< 10) number of users, I don’t think it’ll be as large of a load on the server as you’re thinking. It’s obviously a horrible idea for dozens of users, but if you’re just wanting something to get you by... It would be easy to test out.

EJ

     TUESDAY, JANUARY 29TH, 2008 11:35 AM

6


Dave - Nice Pink Floyd collection.

Ted Williams' Head

     TUESDAY, JANUARY 29TH, 2008 9:01 PM

7




Comments have been turned off since I moved over to Humzoo.