type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end;
var Form1: TForm1;
implementation
{$R *.dfm}
uses MMSystem;
function GetWaveData(FilePath: string; var stream: TMemoryStream): Boolean; var hFile: HMMIO; ckiRIFF,ckiData: TMMCKInfo; begin Result := False; hFile := mmioOpen(PChar(FilePath), nil, MMIO_READ); if hFile = 0 then Exit;
//再获取 data 块的信息后, 指针将自动指向 data 数据的起点; 然后读出数据 if (ckiRIFF.ckid = FOURCC_RIFF) and (ckiRIFF.fccType = mmioStringToFOURCC('WAVE',0)) then if mmioDescend(hFile, @ckiData, @ckiRIFF, MMIO_FINDCHUNK) = MMSYSERR_NOERROR then begin stream.Size := ckiData.cksize; if mmioRead(hFile, stream.Memory, ckiData.cksize) = ckiData.cksize then Result := True; end; mmioClose(hFile, 0); end;
//调用测试 procedure TForm1.Button1Click(Sender: TObject); const FilePath = 'C:/WINDOWS/Media/Windows XP 启动.wav'; var stream: TMemoryStream; b: Byte; str: string; begin stream := TMemoryStream.Create;
if GetWaveData(FilePath, stream) then ShowMessageFmt('读出的数据大小是: %d', [stream.Size]); {424600}