How to get the size and duration of an mp3 file?

I need to calculate the total length of an mp3 file.

I am currently using the PHP class that I found @ http://www.zedwood.com/article/php-calculate-duration-of-mp3 .

This works great if the mp3 file is on the same server.

but if I have a URL from another site, it throws an error. Please help me.

Is there a J-Query JavaScript function to get the length of an mp3 file.

<?php include("mp3.class.php"); $f = 'http://cdn.enjoypur.vc/upload_file/5570/5738/5739/7924/Blue%20Eyes%20-%20Yo%20Yo%20Honey%20Singh%20(PagalWorld.com)%20-192Kbps%20.mp3'; $m = new mp3file($f); $a = $m->get_metadata(); if ($a['Encoding']=='Unknown') echo "?"; else if ($a['Encoding']=='VBR') print_r($a); else if ($a['Encoding']=='CBR') print_r($a); unset($a); ?> 
+7
source share
4 answers

In fact, there is a library that can work on the client side, trying to extract enough MP3 to read ID3 tags:

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

or

Try

HTML file API.

http://lostechies.com/derickbailey/2013/09/23/getting-audio-file-information-with-htmls-file-api-and-audio-element/

+3
source

Use the getID3() PHP library, which also works for VBR files.

This link will help you sourceforge.net .

He is very actively developing.

0
source

Famous and very SPI that you can use MP3 SPI and the code is also very simple

 File file = new File("filename.mp3"); AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file); Map properties = baseFileFormat.properties(); Long duration = (Long) properties.get("duration"); 
0
source

Here is how you can get mp3 duration using Web Audio API:

 const mp3file = 'https://raw.githubusercontent.com/prof3ssorSt3v3/media-sample-files/master/doorbell.mp3' const audioContext = new (window.AudioContext || window.webkitAudioContext)() const request = new XMLHttpRequest() request.open('GET', mp3file, true) request.responseType = 'arraybuffer' request.onload = function() { audioContext.decodeAudioData(request.response, function(buffer) { let duration = buffer.duration console.log(duration) document.write(duration) } ) } request.send() 
0
source

All Articles