How to store audio files for my website?

Hey guys,
I am working on this website for a friend who is a musician. I am making a website where people can stream his songs (around 23-24 songs). How do I store these audio files? Storing it with other files causes a longer loading time for the website. What technique or service do I use to optimize loading time for the website?
I was away from web development for over a year, so having troubles.
Thanks a lot in advance for your help.

Every system I know of that stores large numbers of big files stores them externally to the database. You store all of the queryable data for the file (title, artist, length, etc) in the database, along with a partial path to the file. When it’s time to retrieve the file, you extract the file’s path, prepend some file root (or URL) to it, and return that.

So, you’d have a “location” column, with a partial path in it, like “a/b/c/1000”, which you then map to: “http://myserver/files/a/b/c/1000.mp3

Make sure that you have an easy way to point the media database at a different server/directory, in case you need that for data recovery. Also, you might need a routine that re-syncs the database with the contents of the file archive.

…"

Original Answer: Stack Overflow

1 Like

I would consider using a service, like soundcloud. It has an API and you can embed the player on your site. That may also give the artist more exposure by being on a music platform. Or use some other CDN service for the files.

There are pros and cons. Not hosting the files gives you less control but likely better performance and is a more cost-effective approach because you do not have to pay for the storage or bandwidth.

4 Likes

I’ll second @lasjorg’s suggestion: use a third-party service for this. The hard part isn’t storing and retrieving the music files, it’s the streaming. Running a streaming server is fiddly to an extreme, and not at all cheap.

2 Likes

When looking for services to host files, consider the audiences’ location. For example, SoundCloud seems to be blocked in China, so unless users have a VPN, nobody will be able to listen from there.

If the web host does not meter the bandwidth, like the one I use, and you have plenty of storage, why not use the HTML <audio> tag in the website with controls, and supply an mp3 and ogg file? Maybe flac would be better quality than mp3. I’m not sure about browser support for that.


1 Like