Thema: mp3 duration

Einzelnen Beitrag anzeigen

Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#5

Re: mp3 duration

  Alt 4. Apr 2009, 08:55
Try Audio Tools Library 2.3 it works with CBR and VBR
http://mac.sourceforge.net/atl/


AudioGenie is a fast 32Bit ActiveX-OCX/Dll with over 345 functions to read
audio file information (like Bitrate, Samplerate, Frames, Duration, Version-Number, etc).
http://www.audiogenie.de/en/index.htm

Or

Bass.dll (http://www.un4seen.com/)
Delphi-Quellcode:

function TAudioEngine.Get_MP3_Bitrate: WORD;
const
MPEG_BIT_RATES: array[1..3] of array[1..3] of array[0..15] of word = ((
      { Version 1, Layer I }
      (0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0),
      { Version 1, Layer II }
      (0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0),
      { Version 1, Layer III }
      (0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0)),
      { Version 2, Layer I }
      ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
      { Version 2, Layer II }
      (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
      { Version 2, Layer III }
      (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)),
      { Version 2.5, Layer I }
      ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
      { Version 2.5, Layer II }
      (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
      { Version 2.5, Layer III }
      (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)
    ));
var
  framehead, fpos: DWORD;
  Version, layer, bitrate_index: DWORD;
  fHandle : integer;
  FileFS : THandleStream;
begin

    fpos := BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_DECODE) +
            BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_START);

    fHandle := CreateFile(PChar(Cur_FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE,0);
 if fHandle = INVALID_HANDLE_VALUE then
  exit;
   FileFS := THandleStream.Create(fHandle);
   FileFS.Seek(fpos, soFromBeginning);
   FileFS.Read(framehead, SizeOf(framehead));
   FileFS.Free;
  CloseHandle(fHandle);
  framehead := ((framehead and $ff) shl 24) or
               ((framehead and $ff00) shl 8) or
               ((framehead and $ff0000) shr 8) or
               ((framehead and $ff000000)shr 24); // reverse byte order

  if ((framehead shr 21) = $7ff) then // got frame sync
   begin
    layer := (framehead shr 19) and 3;
    version := (framehead shr 17) and 3;
    bitrate_index := (framehead shr 12) and 15;
    Result := MPEG_BIT_RATES[version][layer][bitrate_index];
  end
 else
  Result:= 0;
end;

Only for CBR (Bass.dll)

Delphi-Quellcode:
var
  fFileSize, fBitRate : DWORD;
  fFloatPos : FLOAT;

  fFileSize:= BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_END);
  fFloatPos:= BASS_ChannelBytes2Seconds(Channel, BASS_StreamGetLength(Channel));


        fBitRate:= Trunc((fFileSize /(125 * fFloatPos))+0.5);
       if Odd(fBitRate) then
        Dec(fBitRate);
      Result:= fBitRate;



have fun
  Mit Zitat antworten Zitat