audio streaming server

2019-05-21 09:55发布

问题:

I'm a php developer, trying to develop a website to stream on-demand music to the users. After a lot of googling I'm confused about which kind of server or tools should I use? I've seen some like WOWZA or SHOUTCAST, but I don't know which one is the best for my needs.

I want to provide high quality audio files. So maybe I should use 320kbps mp3 format or something else but with the same quality.

I don't need live streaming. I just need on-demand streaming of the music files and the ability for the user to create his/her own playlists.

The user shouldn't be able to download the music files.

回答1:

Icecast/SHOUTcast are not appropriate for your use. They take a single stream and send it to multiple connections simultaneously. They are not "on-demand" servers where each user can listen to separate content.

For your use case, you can implement something in PHP. All you are really doing is sending media files to the client. You mentioned that you wanted to keep the client from downloading those files... this is impossible. If the client can play it, the client can save it, and there is no way around this. However, there are some things you can do that prevent it from being as easy as linking to a file.

Don't store your audio in the web server's document root. All media files should be served only from your PHP scripts. This gives you control over the requests coming in. Look into readfile(). This also allows you an easy path to get off of simply loading files from disk (which you will want when you start to grow beyond 100k media files).

A URL for a media file should only work once, and for a specific user session ID. Generate these URLs on the fly, with a time limit on them. If the URL for the media file is requested by someone who doesn't have a valid session on your site, don't serve it. If the link is expired, don't serve it. This is what prevents someone from getting the URL and posting it on some message board. Only valid users of your site with current valid sessions should be able to get at your media files.

Rate-limit requests. Don't allow a user to be able to download more files at a time than is needed. If they request 100 files in 1 second, don't serve them.

Implementing all of these concepts is something I leave to you. How you do so depends your needs, and is not something that is typically done in a 5-line snippet of code.