简体   繁体   English

如何用jQuery / Javascript播放二进制MP3流?

[英]How to play binary MP3 stream with jQuery/Javascript?

I'm getting a pure binary MP3 stream from an ajax call. 我从ajax调用中获得了纯二进制MP3流。 No headers, nothing. 没有标题,没有。 Just straight MP3 bits. 只是直接MP3位。 (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? 如果不可能,还有哪些其他方法可以解决这个问题?

You cant play music with pure javascript. 你不能用纯javascript播放音乐。 you will need to get that stream and pass it to a flash player. 你需要获得该流并将其传递给flash播放器。

try JW flash player , though i am not sure if it can handle the type of stream you are talking about. 试试JW flash播放器 ,虽然我不确定它是否可以处理你所说的流类型。 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. 确实提到过,你需要一个mp3播放插件,闪存是最广泛使用的。 The JMP3 jquery plugin makes that task easier for you. JMP3 jquery插件使您可以更轻松地完成该任务。 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. 如果您只定位非常现代的浏览器 ,则可以使用数据URL:s,只需将对象元素写入HTML,然后链接到该数据URL即可。 Note: I havn't tried this. 注意:我没试过这个。

You might want to look at SoundManager 2: Javascript Sound for the Web 您可能想要查看SoundManager 2:Web的Javascript声音

Its an open-source BSD licensed JavaScript script for dealing with sound. 它是一个开源的BSD许可JavaScript脚本,用于处理声音。

It automatically hooks into HTML5 or Flash to produce the sound, depending on what is available. 它会自动挂钩到HTML5或Flash中以产生声音,具体取决于可用的内容。

I have done this using data uris and there is the browser compatibility 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). 我使用数据uris做了这个,并且存在浏览器兼容性问题,存在url长度的问题(基本上>大约30,000个字符将不支持IE)并且还存在浏览器需要永久解码base64值的问题(缓冲也很慢)。

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. 使用当前的Web技术,我想说最好的办法是将数据写入服务器上的临时文件,然后让Dewplayer加载临时文件并播放它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM