مجموعة من أكواد التعامل مع الصوتيات
#2
ها نحن نعود من جديد مع المجموعة الثانية من اكواد التعامل مع الصوتيات وإليكم الأكواد:

فحص فيما إذا كان TMediaPlayer قد توقف عن تشغيل الصوت
PHP كود :
procedure TForm1.FormCreate(Sender: TObject);
begin
  MediaPlayer1
.Notify   := True;
  
MediaPlayer1.OnNotify := NotifyProc;
end;

procedure TForm1.NotifyProc(Sender: TObject);
begin
  with Sender 
as TMediaPlayer do 
  
begin
    
case Mode of
      mpStopped
: {do something here};
    
end;
    
//must set to true to enable next-time notification
    
Notify := True;
  
end;
end; 


تحديد عرض المجال أو ال bitrate لملف ال WAV

PHP كود :
{....}

  private
    
procedure OpenMedia(WaveFile : string);
    function 
GetStatus(StatusRequested : DWord) : longint;
    
procedure CloseMedia;

{....}

var
  
MyError, dwFlags: Longint;
  
FDeviceID : Word;

{....}

uses
  MMSystem
;

{....}

procedure TForm1.OpenMedia(WaveFile: string);
var
  
MyOpenParms: TMCI_Open_Parms;
begin
  with MyOpenParms 
do
  
begin
    dwCallback       
:= Handle; // TForm1.Handle
    
lpstrDeviceType  := PChar('WaveAudio');
    
lpstrElementName := PChar(WaveFile);
  
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, here to specify a particular device
  
if MyError = 0 then
    FDeviceID 
:= MyOpenParms.wDeviceID
  
else
    
raise Exception.Create('Open Failed');
end;

function 
TForm1.GetStatus(StatusRequested: DWORD): Longint;
var
  
MyStatusParms: TMCI_Status_Parms;
begin
  dwFlags 
:= MCI_WAIT or MCI_STATUS_ITEM;
  
with MyStatusParms do
  
begin
    dwCallback 
:= Handle;
    
dwItem     := StatusRequested;
  
end;
  
MyError := mciSendCommand(FDeviceID,
    
MCI_STATUS,
    
MCI_WAIT or MCI_STATUS_ITEM,
    
Longint(@MyStatusParms));
  if 
MyError = 0 then
    Result 
:= MyStatusParms.dwReturn
  
else
    
raise Exception.Create('Status call to get status of ' +
      
IntToStr(StatusRequested) + ' Failed');
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 Exception
.Create('Close Failed');
    
end;
  
end;
end;


//Example:
//Beispiel:

procedure TForm1.Button1Click(Sender: TObject);
begin
  
if OpenDialog1.Execute then
  begin
    OpenMedia
(OpenDialog1.FileName);
    
with ListBox1.Items do
    
begin
      Add
('Average Bytes / Sec : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_AVGBYTESPERSEC)));
      
Add('Bits / Sample : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_BITSPERSAMPLE)));
      
Add('Samples / Sec : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_SAMPLESPERSEC)));
      
Add('Channels : ' + IntToStr(GetStatus(MCI_WAVE_STATUS_CHANNELS)));
    
end;
    
CloseMedia;
  
end;
end; 


فحص فيما إذا كان Macromedia Flash plugin منصب أو موجود على النظام:


PHP كود :
uses
  Forms
, Windows, INIFiles, SysUtils, Dialogs, ShellApi;

{
$R *.RES}

type
  TVersionInfo 
= record
    dwSignature
,
    
dwStrucVersion,
    
dwFileVersionMS,
    
dwFileVersionLS,
    
dwProductVersionMS,
    
dwProductVersionLS,
    
dwFileFlagsMask,
    
dwFileFlags,
    
dwFileOS,
    
dwFileType,
    
dwFileSubtype,
    
dwFileDateMS,
    
dwFileDateLS: DWORD;
  
end;


var
  
//Reg:TRegistry;
  
Ini: TIniFile;
  
Text: array[1..4] of string;

  
AppPath, IniFile, MySec: string;
  
SetupFile, RunFile, SetupClass: string;

  
VersionStr, BrowserStr: string;

  {
RegSubKey,} OpenBrowser, PlugInName, UseExt: string;
  
MainVersion: Word;
  
// FoundOne :Boolean;

  
PVer, DPchar, POpenBrowser: PChar;
  
MyPoint: Pointer;
  
PLen: Cardinal;
  
version: ^TVersionInfo;
  
DumD: DWORD;
  
LWord, HWord: Word;

  
CheckHandle: Hwnd;

  
//---------------------------
  //Gets the Plugin (file-) Version
  //---------------------------
procedure GetVersion(pluginName: string);
begin
  DPChar 
:= StrAlloc(255);
  
DPchar := PChar(PluginName);

  
PVer := StrAlloc(getFileVersionInfoSize(DPchar, Plen));
  
getFileVersionInfo(DPChar, 0, 255, PVer);
  
VerQueryValue(Pver, '\', MyPoint, Plen);

  Version := myPoint;

  dumD  := Version.dwFileVersionMS;
  hword := dumD shr 16;
  lword := dumD and 255;

  MainVersion := hword;
  VersionStr  := IntToStr(Hword) + '
.' + IntToStr(LWord);

  dumD  := Version.dwFileVersionLs;
  hword := dumD shr 16;
  lword := dumD and 255;

  versionStr := versionStr + '
.' + IntToStr(Hword) + '.' + IntToStr(lWord);
end;

begin
  appPath := extractFileDir(Application.exeName);


  // runFile:= '
test.htm';
  //runFile must be a html File to determin wich browser(NC or IE) is used
  POpenBrowser := StrAlloc(255);
  FindExecutable(PChar(extractFileName(runFile)),
    PChar(extractFileDir(runFile)), POpenBrowser);
  OpenBrowser := POpenBrowser;

  if not Fileexists(openBrowser) then
  begin
    MessageDlg(Text[4], mtInformation, [mbOK], 0);
    halt;
  end;


  //set the FileLocations for Netscape or IE
  if Pos('
NETSCAPE.EXE', uppercase(trim(OpenBrowser))) <> 0 then
  begin //found Netscape
    BrowserStr := '
Netscape Comunicator';
    PlugInName := Copy(OpenBrowser, 1, Pos('
NETSCAPE.EXE',
      uppercase(trim(OpenBrowser))) - 1);
    PluginName := PlugInName + '
Plugins\NPSWF32.dll';
  end
  else
  //found IEExplorer
  begin
    BrowserStr := '
Internet Explorer';

    DPChar := StrAlloc(255);
    GetSystemDirectory(DPChar, 255);
    PluginName := DPChar + '
\Macromed\Flash\swflash.ocx';
    DPChar     := nil;
  end;

  GetVersion(pluginName);

  //returned Version Number, may be checked
  while mainVersion < 4 do
  begin
    if messagedlg(Text[2], mtInformation, [mbYes, mbNo], 0) = 6 then
    begin
      //installFlash;
    end
    // if message
    else
      halt;

    getVersion(pluginName);
  end; // while mainVer
end. 



هنالك أيضاً مجموعة أخرى أتمنى أن تعجبكم هذه المجموعة....
الرد


الردود في هذا الموضوع
مجموعة من أكواد التعامل مع الصوتيات - بواسطة issamdnn - 18-01-2010, 08:46 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم