Mp3 Length in Milliseconds

mp3 length in milliseconds

http://id3lib-ruby.rubyforge.org/ ? This page has the code you need.

Calculating the length of MP3 Frames in milliseconds

I used different approach to calculate the time of every frame in the mp3 file..
assuming that all frames have same size in the file.. so I just get the total time of the mp3 file in milliseconds.. then calculate total frames in the file and finally divide the total time by total frames.. so the formula would look like:

float frameTime = totalTimeMillisec / totalFrames;

you will get the total time of every frame in the track in milliseconds..
after I done that I got around 52 milliseconds... and that was similar to what Mark Heath said..

anyway thanks everybody for the solutions..

Get Mp3 total duration in seconds (or millisecond) using Media Foundation

MS Media Foundation can give you attributes of MP3 files, including duration. There's a sample app on Github, and the relevant code is excerpted here. This is not my code, and it won't work out-of-the-box with the asynchronous interface given by StorageFile, but the job of fitting square pegs into round holes is pretty straight-forward.

Note that Duration here is in 100-nanosecond ticks, per the MF_PD_DURATION documentation on MSDN.

#include <collection.h>
#include <ppltasks.h>
#include <mfidl.h>
#include <mfapi.h>
#include <mfreadwrite.h>
#include <wrl.h>

#pragma comment(lib, "mf.lib")
#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfuuid.lib")

using namespace Platform;
using namespace Windows::Storage::Streams;
using namespace Microsoft::WRL;

// Only throw in exception based code (C++/CX), never throw in HRESULT error code based code.
#define THROW_IF_FAILED(hr) { if (FAILED(hr)) throw Platform::Exception::CreateException(hr); }
#pragma comment(lib, "mfreadwrite.lib")

namespace MFUtils
{
// This WinRT object provides JavaScript or C# code access to the information in the stream
// that it needs to construct the AudioEncodingProperties needed to construct the AudioStreamDescriptor
// needed to create a MediaStreamSource. Here is how to create it
// var helper = new MFUtils.MFAttributesHelper(self.memoryStream, data.mimeType);

public ref class MFAttributesHelper sealed
{
public:
property UINT64 Duration;
property UINT32 BitRate;
property UINT32 SampleRate;
property UINT32 ChannelCount;

// The synchronous design only works with in memory streams.
MFAttributesHelper(InMemoryRandomAccessStream^ stream, String^ mimeType)
{
THROW_IF_FAILED(MFStartup(MF_VERSION));
// create an IMFByteStream from "stream"
ComPtr<IMFByteStream> byteStream;
THROW_IF_FAILED(MFCreateMFByteStreamOnStreamEx(reinterpret_cast<IUnknown*>(stream), &byteStream));

// assign mime type to the attributes on this byte stream
ComPtr<IMFAttributes> attributes;
THROW_IF_FAILED(byteStream.As(&attributes));
THROW_IF_FAILED(attributes->SetString(MF_BYTESTREAM_CONTENT_TYPE, mimeType->Data()));

// create a source reader from the byte stream
ComPtr<IMFSourceReader> sourceReader;
THROW_IF_FAILED(MFCreateSourceReaderFromByteStream(byteStream.Get(), nullptr, &sourceReader));

// get current media type
ComPtr<IMFMediaType> mediaType;
THROW_IF_FAILED(sourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, &mediaType));

// get all the data we're looking for
PROPVARIANT prop;
THROW_IF_FAILED(sourceReader->GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE, MF_PD_DURATION, &prop));
Duration = prop.uhVal.QuadPart;

UINT32 data;
THROW_IF_FAILED(sourceReader->GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE, MF_PD_AUDIO_ENCODING_BITRATE, &prop));
BitRate = prop.ulVal;

THROW_IF_FAILED(mediaType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &data));
SampleRate = data;

THROW_IF_FAILED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &data));
ChannelCount = data;
}

private:
~MFAttributesHelper()
{
MFShutdown();
}
};
}

Finding the length of an MP3 file in java, preferably in milliseconds, just like python's mutagen library

There is no simple way to get the playing length of an MP3, the format does not contain a specified "length" anywhere; it was designed with streaming in mind.

The only way is to parse the MP3 frames and count them, taking into account their sampling rate. This isn't entirely trivial to implement, so using a library is the simplest option: Finding Duration of an MP3 file in Java

time length of an mp3 file

You can use pymad. It's an external library, but don't fall for the Not Invented Here trap. Any particular reason you don't want any external libraries?

import mad

mf = mad.MadFile("foo.mp3")
track_length_in_milliseconds = mf.total_time()

Spotted here.

--

If you really don't want to use an external library, have a look here and check out how he's done it. Warning: it's complicated.

MP3: a way to get position in milliseconds for any given byte position?

It doesn't work like that. Even if your MP3 file is constant-bit-rate encoded, which byte position encodes which second in the stream is variable. (To be sure, VBR encoding makes it a lot more variable than CBR, but all the same.) The only way to reliably get this information is to actually decode the stream up to that point, which you probably don't want to do. This is why even professional players such as XMMS cannot reliably update the slider when you skip around.

Determine the length (in milliseconds) of an mp3 file in VB.net

I think you are looking for the TagLib.File.Properties.Duration, which returns a TimeSpan object. From there you can use TotalSeconds to get the length of the mp3 in seconds.

Get the time duration of an mp3 file in seconds and milliseconds using Java J2SE

I have this method to play my mp3 file using

      jlayer.jar 
mp3plugin.jar
jaudiotagger-2.0.1.jar

private void playMe(){
try{

File file=new File("F:\\Net Beans Work Space\\mp3\\a.mp3");
FileInputStream fis = new FileInputStream(file);

BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);

int d=0;
AudioFile audioFile = AudioFileIO.read(file);
d = audioFile.getAudioHeader().getTrackLength();

System.out.print("ddd= "+d) ;

player.play();
}catch(Exception e){

System.out.print("ERROR "+e);
}

}

What one must have to do is to create and use Java Threads and the time length using this coding of method is 99% accurate lols

HTML5: How to get currentTime and duration of Audio Tag in milliseconds

You can use:

<audio id="track" controls>
<source src="your.mp3" type="audio/mpeg">
<source src="your.ogg" type="audio/ogg">
</audio>
<script type="text/javascript">
var audio = document.getElementById('track');
audio.addEventListener('timeupdate',function(){
var currentTimeMs = audio.currentTime*1000;
console.log(currentTimeMs);
},false);
</script>

You can read here for more information on the precision of the timeupdate event. It is dependent on the browser implementation so keep in mind you will get different results from a browser/device to another.

You should use addEventListener method rather than the ontimeupdate property - it is more maintainable.

Also if you need browser coverage it is good to use both ogg and mp3 audio files as sources.



Related Topics



Leave a reply



Submit