代码文件:
Unit1; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; TForm1 = (TForm) Button1: TButton; Button2: TButton; Button3: TButton; ScrollBar1: TScrollBar; ScrollBar2: TScrollBar; FormCreate(Sender: TObject); Button1Click(Sender: TObject); Button2Click(Sender: TObject); Button3Click(Sender: TObject); ScrollBar1Change(Sender: TObject); FormDestroy(Sender: TObject); ; Form1: TForm1; MMSystem; GetWaveFmtData(path: ; fmt: TWaveFormatEx; buf: TBytes): Boolean; hFile: HMMIO; ckiRIFF,ckiFmt,ckiData: TMMCKInfo; Result := False; hFile := mmioOpen(PChar(path), , MMIO_READ); hFile = Exit; ZeroMemory(@ckiRIFF, SizeOf(TMMCKInfo)); ZeroMemory(@ckiFmt, SizeOf(TMMCKInfo)); ZeroMemory(@ckiData, SizeOf(TMMCKInfo)); ckiRIFF.fccType := mmioStringToFOURCC(, ); ckiFmt.ckid := mmioStringToFOURCC(, ); ckiData.ckid := mmioStringToFOURCC(, ); ZeroMemory(@fmt, SizeOf(TWaveFormatEx)); mmioDescend(hFile, @ckiRIFF, , MMIO_FINDRIFF); (ckiRIFF.ckid = FOURCC_RIFF) (ckiRIFF.fccType = mmioStringToFOURCC(,)) (mmioDescend(hFile, @ckiFmt, @ckiRIFF, MMIO_FINDCHUNK) = MMSYSERR_NOERROR) (mmioRead(hFile, @fmt, ckiFmt.cksize) = ckiFmt.cksize) (mmioAscend(hFile, @ckiFmt, ) = MMSYSERR_NOERROR) (mmioDescend(hFile, @ckiData, @ckiRIFF, MMIO_FINDCHUNK) = MMSYSERR_NOERROR) SetLength(buf, ckiData.cksize); Result := (mmioRead(hFile, PAnsiChar(buf), ckiData.cksize) = ckiData.cksize); ; mmioClose(hFile, ); ; wh: TWaveHdr; hWaveOut: HWAVE; fmt: TWaveFormatEx; buf: TBytes; TForm1.FormCreate(Sender: TObject); Button1.Caption := ; Button2.Caption := ; Button3.Caption := ; ScrollBar1.Min := ; ScrollBar1.Max := ; ScrollBar2.Min := ; ScrollBar2.Max := ; ScrollBar2.OnChange := ScrollBar1.OnChange; ; TForm1.ScrollBar1Change(Sender: TObject); L,R: Word; hWaveOut = Exit; L := Trunc(ScrollBar1.Position / * MAXWORD); R := Trunc(ScrollBar2.Position / * MAXWORD); waveOutSetVolume(hWaveOut, MakeLong(L, R)); ; WaveProc(hWave: HWAVE; uMsg, dwInstance, dwParam1, dwParam2: DWORD); ; uMsg MM_WOM_DONE: waveOutUnprepareHeader(hWave, PWaveHdr(dwParam1), SizeOf(TWaveHdr)); ; ; TForm1.Button1Click(Sender: TObject); path = ; volume: DWORD; GetWaveFmtData(path, fmt, buf); wh.lpData := PAnsiChar(buf); wh.dwBufferLength := Length(buf); wh.dwBytesRecorded := ; wh.dwUser := ; wh.dwFlags := WHDR_BEGINLOOP WHDR_ENDLOOP; wh.dwLoops := ; wh.lpNext := ; wh.reserved := ; waveOutOpen(@hWaveOut, WAVE_MAPPER, @fmt, DWORD(@WaveProc), , CALLBACK_FUNCTION); waveOutGetVolume(hWaveOut, @volume); ScrollBar1.Position := Trunc(LoWord(volume) / MAXWORD * ); ScrollBar2.Position := Trunc(HiWord(volume) / MAXWORD * ); waveOutPrepareHeader(hWaveOut, @wh, SizeOf(TWaveHdr)); waveOutWrite(hWaveOut, @wh, SizeOf(TWaveHdr)); ; TForm1.Button2Click(Sender: TObject); waveOutPause(hWaveOut); ; TForm1.Button3Click(Sender: TObject); waveOutRestart(hWaveOut); ; TForm1.FormDestroy(Sender: TObject); hWaveOut <> waveOutClose(hWaveOut); ; .
窗体文件:
Form1: TForm1 Left = Top = Caption = ClientHeight = ClientWidth = Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = - Font.Name = Font.Style = [] OldCreateOrder = False OnCreate = FormCreate OnDestroy = FormDestroy PixelsPerInch = TextHeight = Button1: TButton Left = Top = Width = Height = Caption = TabOrder = OnClick = Button1Click Button2: TButton Left = Top = Width = Height = Caption = TabOrder = OnClick = Button2Click Button3: TButton Left = Top = Width = Height = Caption = TabOrder = OnClick = Button3Click ScrollBar1: TScrollBar Left = Top = Width = Height = PageSize = TabOrder = OnChange = ScrollBar1Change ScrollBar2: TScrollBar Left = Top = Width = Height = PageSize = TabOrder =