unit Unit1;//ip电话的一个例子,自己看看
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ACMDialog, ACMWaveIn, ACMWaveOut, StdCtrls, NMUDP, ExtCtrls, Psock,
ComCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
NMUDP1: TNMUDP;
StatusBar1: TStatusBar;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ACMWaveIn1Data(data: Pointer; size: Integer);
procedure NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
PlayPackets:integer;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);//开始
var format
ointer;
begin
NMUDP1.Remotehost:=edit1.text;
format:=ACMDialog1.OpenDialog;
if format=nil then exit;
ACMWaveOut1.Open(format);
ACMWaveIn1.Open(format);
Button1.Enabled:=false;
Button2.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);//停止
begin
ACMWaveIn1.Close;
ACMWaveOut1.Close;
Button1.Enabled:=true;
Button2.Enabled:=false;
end;
procedure TForm1.ACMWaveIn1Data(data: Pointer; size: Integer);
var
mdata:array[1..10000] of char;
k:integer;
str:string;
begin
for k:=1 to size do mdata[k]:=pchar(dword(data)+k-1)^;
NMUDP1.SendBuffer(mdata,size);
end;
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
mdata:array[1..10000] of char;
data
char;
str:string;
k:integer;
begin
NMUDP1.ReadBuffer(mdata,NumberBytes);
data:=pchar(dword(@mdata));
StatusBar1.SimpleText:='Packets:'+inttostr(PlayPackets);
inc(PlayPackets);
ACMWaveOut1.PlayBack(data,NumberBytes);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ACMWaveOut1.visible:=false;
ACMWaveIn1.visible:=false;
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.LocalPort := 6668;
NMUDP1.RemotePort := 6668;
PlayPackets:=0;
end;
end.