Author: Arthur Young How to determinate the bitrate of a WAV file? Answer: 1 {....} 2 3 private 4 5 procedure OpenMedia(WaveFile: string); 6 function GetStatus(StatusRequested: DWord): longint; 7 procedure CloseMedia; 8 9 {....} 10 11 var 12 MyError, dwFlags: Longint; 13 FDeviceID: Word; 14 15 {....} 16 17 uses 18 MMSystem; 19 20 {....} 21 22 procedure TForm1.OpenMedia(WaveFile: string); 23 var 24 MyOpenParms: TMCI_Open_Parms; 25 begin 26 with MyOpenParms do 27 begin 28 dwCallback := Handle; // TForm1.Handle 29 lpstrDeviceType := PChar('WaveAudio'); 30 lpstrElementName := PChar(WaveFile); 31 end; {with MyOpenParms} 32 dwFlags := MCI_WAIT or MCI_OPEN_ELEMENT or MCI_OPEN_TYPE; 33 MyError := mciSendCommand(0, MCI_OPEN, dwFlags, Longint(@MyOpenParms)); 34 // one could use mciSendCommand(DevId, here to specify a particular device 35 if MyError = 0 then 36 FDeviceID := MyOpenParms.wDeviceID 37 else 38 raise Exception.Create('Open Failed'); 39 end; 40 41 function TForm1.GetStatus(StatusRequested: DWORD): Longint; 42 var 43 MyStatusParms: TMCI_Status_Parms; 44 begin 45 dwFlags := MCI_WAIT or MCI_STATUS_ITEM; 46 with MyStatusParms do 47 begin 48 dwCallback := Handle; 49 dwItem := StatusRequested; 50 end; 51 MyError := mciSendCommand(FDeviceID, 52 MCI_STATUS, 53 MCI_WAIT or MCI_STATUS_ITEM, 54 Longint(@MyStatusParms)); 55 if MyError = 0 then 56 Result := MyStatusParms.dwReturn 57 else 58 raise Exception.Create('Status call to get status of ' + 59 IntToStr(StatusRequested) + ' Failed'); 60 end; 61 62 procedure TForm1.CloseMedia; 63 var 64 MyGenParms: TMCI_Generic_Parms; 65 begin 66 if FDeviceID > 0 then 67 begin 68 dwFlags := 0; 69 MyGenParms.dwCallback := Handle; // TForm1.Handle 70 MyError := mciSendCommand(FDeviceID, MCI_CLOSE, dwFlags, Longint(@MyGenParms)); 71 if MyError = 0 then 72 FDeviceID := 0 73 else 74 begin 75 raise Exception.Create('Close Failed'); 76 end; 77 end; 78 end; 79 80 //Example 81 82 procedure TForm1.Button1Click(Sender: TObject); 83 begin 84 if OpenDialog1.Execute then 85 begin 86 OpenMedia(OpenDialog1.FileName); 87 with ListBox1.Items do 88 begin 89 Add('Average Bytes / Sec : ' + 90 IntToStr(GetStatus(MCI_WAVE_STATUS_AVGBYTESPERSEC))); 91 Add('Bits / Sample : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_BITSPERSAMPLE))); 92 Add('Samples / Sec : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_SAMPLESPERSEC))); 93 Add('Channels : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_CHANNELS))); 94 end; 95 CloseMedia; 96 end; 97 end;