was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

28 Visitors Online


 
...die Länge einer Wave-Datei ermitteln?
Autor: AlanGLLoyd
[ Tip ausdrucken ]  

Tip Bewertung (9):  
     


type
  
EMyMCIException = class(Exception);

var
  
FDeviceID: Word;
  MyError, dwFlags: Longint;

procedure TForm1.GetWaveLength;
var
  
WaveLen: DWORD;
begin
  
OpenMedia('C:\Hickory.wav');
  SetMediaTimeFormat;
  WaveLen := GetMediaStatus(MCI_STATUS_LENGTH);
  CloseMedia;
  Form1.label1.Caption := IntToStr(WaveLen) + 'mS';
end;

procedure TForm1.OpenMedia(FileName: string);
var
  
MyOpenParms: TMCI_Open_Parms;
begin
  with 
MyOpenParms do
  begin
    
dwCallback := Handle; // TForm1.Handle
    
lpstrDeviceType := PChar('WaveAudio');
    lpstrElementName := PChar(FileName);
  end{with MyOpenParms}
  
dwFlags := MCI_WAIT or MCI_OPEN_ELEMENT or MCI_OPEN_TYPE;
  MyError := mciSendCommand(0, MCI_OPEN, dwFlags, Longint(@MyOpenParms));
  // one could use mciSendCommand(DevId, etc here to specify a particular
  
device
  if MyError = 0 then
    
FDeviceID := MyOpenParms.wDeviceID
  else
    raise 
EMyMCIException.Create('Open Failed');
end;

procedure TForm1.SetMediaTimeFormat;
var
  
MySetParms: TMCI_Set_Parms;
begin
  if 
FDeviceID <> 0 then
  begin
    
dwFlags := MCI_WAIT or MCI_SET_TIME_FORMAT;
    MySetParms.dwCallback := Handle; // TForm1.Handle
    
MySetParms.dwTimeFormat := MCI_FORMAT_MILLISECONDS;
    MyError := mciSendCommand(FDeviceID, MCI_SET, dwFlags,
      Longint(@MySetParms));
    if MyError <> 0 then
      raise 
EMyMCIException.Create('Status Failed');
  end;
end;

function TForm1.GetMediaStatus(StatusItem: DWORD): DWORD;
var
  
MyStatusParms: TMCI_Status_Parms;
begin
  if 
FDeviceID <> 0 then
  begin
    
dwFlags := MCI_WAIT or MCI_STATUS_ITEM;
    MyStatusParms.dwCallback := Handle; // TForm1.Handle
    
MyStatusParms.dwItem := StatusItem;
    MyError := mciSendCommand(FDeviceID, MCI_STATUS, dwFlags,
      Longint(@MyStatusParms));
    if MyError = 0 then
      
Result := MyStatusParms.dwReturn
    else
    begin
      raise 
EMyMCIException.Create('Status Failed');
    end;
  end;
end;

procedure TForm1.CloseMedia;
var
  
MyGenParms: TMCI_Generic_Parms;
begin
  if 
FDeviceID <> 0 then
  begin
    
dwFlags := 0;
    MyGenParms.dwCallback := Handle; // TForm1.Handle
    
MyError := mciSendCommand(FDeviceID, MCI_CLOSE, dwFlags,
      Longint(@MyGenParms));
    if MyError = 0 then
      
FDeviceID := 0
    else
    begin
      raise 
EMyMCIException.Create('Close Failed');
    end;
  end;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners