3

I have a Ruby On Rails application running on Nginx which is serving out MP3s using JW player. I need to be able to set the start time and duration for playlist items. From what I can tell to do this I need be streaming the MP3 files. How can I setup Nginx to do this?

3 Answers 3

1

Nginx has built in support for streaming FLV files through the HttpFlvStreamModule. You nave to specify the module when you compile / recompile Nginx.

# ./configure --with-http_flv_module ...SOME-OTHER-OPTS...

You can then configure your nginx.conf to stream FLV files like so:

...
http {
    ...
    server {
        ...
        location ~ \.flv$ {
            flv;
        }
        ...
    }
    ...
}

Now how does this help anything since the original question was about streaming MP3 files? Well you can use FFMPEG to convert the MP3s to FLV files like this:

ffmpeg -y -i /home/song.mp3 -f flv -acodec mp3 -ab 64 -ac 1 /home/song.flv
2
  • I guess that's cool if you like to use a video player to play music. I've used this before: flash-mp3-player.net There are quite a few other flash audio players as well.
    – d-_-b
    Feb 10, 2011 at 1:48
  • No need to deal with FLV for this, there is no extra streaming server requirement beyond HTTP in this use case. Also, if you're going to convert from MP3 to FLV, you should use -acodec copy... otherwise you're transcoding and reducing quality.
    – Brad
    Apr 22, 2017 at 5:40
0

AFAIK, Nginx is an HTTP server. To stream audio, you will need the likes of Icecast: http://www.icecast.org/

The technical differences between streaming and downloading are mainly with the client and server. To the end user, streaming means that they probably will not be able to save media on their machine. Download and the end user may not be able to begin watching it right away. Though in practice, most data can be viewed as soon as the first bits arrive at the client.

That being said, are you sure you need a streaming server to use JWplayer? Can't you just point it to a URL and let JW fetch it? In this case, Nginx would serve the audio just fine.

In fact, I'm pretty sure I've done this before with Apache. The video started playing after a bit of buffering - like it does with Youtube.

3
  • According to the JW player you need to be using streaming vs flat file served by a web-server in order to specify the "start" parameter. Shown in their documentation
    – bwizzy
    Feb 9, 2011 at 11:43
  • JWplayer supports stream for video. "Support for streaming video protocols RTMP and HTTP pseudo-streaming" longtailvideo.com/support/jw-player/jw-player-for-flash-v5/… I see no mention of support for streaming audio. What is you use case and why do you want to use a streaming protocol with MP3?
    – d-_-b
    Feb 10, 2011 at 1:29
  • This answer is wrong. This content is served on-demand, over HTTP, and that's how it is streamed. Icecast is for live streams, and actually uses HTTP as well.
    – Brad
    Apr 22, 2017 at 5:35
0

You can also achieve this with mp4 module

 location /mp3/ {
    root data;
    mp4;
    mp4_buffer_size      1m;
    mp4_max_buffer_size  5m;
 }

You don't have to convert to flv to play mp3

1
  • Nope, you can not. If you will try to position isnide mp3 files you will get the error mp4 atom too large since mp3 files miss the required metadata.
    – drookie
    Nov 19, 2023 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .