Hi All
Can someone give me the formula for calculating the play time in milliseconds of a MP3 file as I need to show progress time resolution to .1 seconds for my app
Thanks in advance
Mp3 frame header: http://www.mp3-tech.org/programmer/frame_header.html
The total length you can calculate by multiplying number of valid frames by 20ms (if I remember each frame is 20ms long).
Alternative way gives directshow. Create IGraphBuilder (CLSID_FilterGraph), call RenderFile, query IMediaPosition interface and use IMediaPosition::get_Duration. It returns the duration in seconds as a REFTIME (double) type. Finally query IMediaControl interface and call Stop method.
I have nasm example:%include "macros.inc"
$use "d:\\aurora\\libs\\sdk\\strmiids.lib"
extern _CLSID_FilterGraph
extern _IID_IGraphBuilder
extern _IID_IMediaControl
extern _IID_IMediaPosition
segment .data
time dd 0,0
graph dd 0
pos dd 0
ctrl dd 0
buff dd 0,0,0,0,0
segment .text
; method indexes
QueryInterface equ 4*0
RenderFile equ 4*13
get_Duration equ 4*7
Stop equ 4*9
Release equ 4*2
main:
invoke CoInitialize, 0
invoke CoCreateInstance, _CLSID_FilterGraph, 0, 1, _IID_IGraphBuilder, graph
and eax,eax
jnz near quit
coinvoke [graph], QueryInterface, _IID_IMediaControl, ctrl
coinvoke [graph], QueryInterface, _IID_IMediaPosition, pos
coinvoke [graph], RenderFile, L"M:\\music.mp3", 0
coinvoke [pos], get_Duration, time
coinvoke [ctrl], Stop
coinvoke [graph], Release
coinvoke [ctrl], Release
coinvoke [pos], Release
cinvoke sprintf, buff, "%fs", [time], [time+4]
invoke MessageBoxA, 0, buff, 0, 0
quit:
invoke CoUninitialize
invoke ExitProcess, eax
ret