开发者

get mp3 song duration in javascript

开发者 https://www.devze.com 2023-01-10 04:13 出处:网络
is there a way to get mp3 s开发者_StackOverflowong duration in JavaScript? Thanks.That depends on what environment the JS is running in.

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

精彩评论

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

关注公众号