admin管理员组

文章数量:1304184

I'm getting a pure binary MP3 stream from an ajax call. No headers, nothing. Just straight MP3 bits. (Actually is that really even a stream at all?)

I'd like to be able to play it in a web page (and, if possible, offer it for downloading).

Is this possible? And if so what's the best way to do it?

If it is not possible, what are some other ways to handle this?

I'm getting a pure binary MP3 stream from an ajax call. No headers, nothing. Just straight MP3 bits. (Actually is that really even a stream at all?)

I'd like to be able to play it in a web page (and, if possible, offer it for downloading).

Is this possible? And if so what's the best way to do it?

If it is not possible, what are some other ways to handle this?

Share Improve this question asked Jul 23, 2009 at 19:09 thermansthermans 1,1672 gold badges14 silver badges24 bronze badges 3
  • Should have mentioned that I know I need a flash player or something like it. I was most interested in how to play a stream of this type without a URL or a file... – thermans Commented Jul 23, 2009 at 19:23
  • so the ajax response contains a string which holds the entire mp3 file? or does the response give you a url of that stream? – mkoryak Commented Jul 23, 2009 at 19:39
  • The former. A string with just the binary mp3 data. – thermans Commented Jul 23, 2009 at 20:23
Add a ment  | 

5 Answers 5

Reset to default 2

You cant play music with pure javascript. you will need to get that stream and pass it to a flash player.

try JW flash player, though i am not sure if it can handle the type of stream you are talking about. you will have to do some research about what it can handle

as indeed mentioned, you'll need a mp3 playing plugin, flash being the most widely available. The JMP3 jquery plugin makes that task easier for you. It does rely on a flash file for the sound processing.

If you're only targeting very modern browsers, you could make use of data URL:s, and just write an object element to your HTML, and link to that data URL. Note: I havn't tried this.

You might want to look at SoundManager 2: Javascript Sound for the Web

Its an open-source BSD licensed JavaScript script for dealing with sound.

It automatically hooks into HTML5 or Flash to produce the sound, depending on what is available.

I have done this using data uris and there is the browser patibility issue, there is the problem of url length (basically > about 30,000 characters won't support IE) and there is also the problem of the browser taking forever to decode the base64 value (the buffering is also extermely slow).

With current web technology, I would say your best bet is to write the data to a temporary file on your server and then have something like Dewplayer load the temporary file and play it.

本文标签: How to play binary MP3 stream with jQueryJavascriptStack Overflow