开发者

get mp3 song duration in javascript

is there a way to get mp3 s开发者_StackOverflowong duration in JavaScript?

Thanks.


That depends on what environment the JS is running in.

If you are in a browser which supports mp3 and the HTML5 audio API, then you can load the mp3 in an <audio> element and access the duration property via the DOM. If you are using some sort of Flash player, then it might expose that information using ExternalInterface.

There are other environments, but they aren't in such common usage.


There is actually a library that can run client-side, attempting to fetch just enough of the MP3 to read the ID3 tags:

http://github.com/aadsm/JavaScript-ID3-Reader

Since you are using server-side JavaScript, you can directly read files from the server and do pretty much anything you want. If you can't find any libraries specifically for server-side use, I expect you can grab just the bits out of the above project that relate to parsing the ID3, and leave out the AJAX fetching stuff.

Other libraries are available with a Web search for Javascript ID3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜