unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MPEGPlay, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
MPlayer: TMPEGPlayer;
OpenDialog1: TOpenDialog;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CallBackCreateStream (var cant_seek:boolean; var res
ointer);
procedure CallBackCloseStream (handle
ointer);
procedure CallBackRestartStream (handle
ointer; var res:boolean);
procedure CallBackReadStream (handle
ointer;
var read_buffer;
nNumberOfBytesToRead:longint;
var nNumberOfBytesRead:longInt; var res:boolean);
procedure CallBackSeekStream (handle
ointer;
NumBytes,MoveMethod:LongInt; var res:LongInt);
procedure CallBackGetStreamSize (handle
ointer; var res:longint);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not OpenDialog1.Execute then exit;
MPlayer.StreamName:=OpenDialog1.FileName;
MPlayer.Open;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MPlayer.init;
MPlayer.OnOpenStream:=CallBackCreateStream;
MPlayer.OnCloseStream:=CallBackCloseStream;
MPlayer.OnRestartStream:=CallBackRestartStream;
MPlayer.OnGetStreamSize:=CallBackGetStreamSize;
MPlayer.OnSeekStream:=CallBackSeekStream;
MPlayer.OnReadStream:=CallBackReadStream;
end;
procedure TForm1.CallBackCreateStream;
var t:TFileStream;
begin
t:=TFileStream.Create(MPlayer.StreamName, fmOpenRead or fmShareExclusive);
res:=pointer(t);
Cant_seek:=false;
end;
procedure TForm1.CallBackCloseStream;
begin
TFileStream(handle).free;
end;
procedure TForm1.CallBackRestartStream;
begin
res:=((TFileStream(handle).Seek(0,soFromBeginning))=0);
end;
procedure TForm1.CallBackReadStream;
begin
nNumberOfBytesRead:=TFileStream(handle).Read(read_buffer, nNumberOfBytesToRead);
res:=true;
end;
procedure TForm1.CallBackSeekStream;
begin
res:=(TFileStream(handle).Seek(NumBytes,MoveMethod));
end;
procedure TForm1.CallBackGetStreamSize;
begin
res:=TFileStream(handle).Size;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
MPlayer.play;
end;
end.