如何用Delphi自带的控件播放VCD(100分)

  • 主题发起人 主题发起人 柳枫
  • 开始时间 开始时间

柳枫

Unregistered / Unconfirmed
GUEST, unregistred user!
无论我如何试也不行!!!
请教大家!
谢谢!
柳枫
 
mediaplayer的devicetype一定要设置为dtAutoselect
 
是 DAT 文件吗?要改注册文件。
 
是 DAT 文件,要改注册文件?如何改?
可以给出示例吗?
谢谢!
柳枫
 
请在程序中加入一下两行,就可以播放DAT文件了,或者是在win.ini文件中手工加入也可。
WritePrivateProfileString('mci extensions', 'dat', 'MPEGVideo', 'win.ini');
WritePrivateProfileString('mci extensions', 'AVI', 'AVIVideo', 'win.ini');
请记住把分给我。
 
以下程序不仅可以播放vcd,还可以把视频帧转化成一张张bmp文件保存

不过播放什么格式的视频mediaplayer的devicetype就设置成什么,或者直接设置为dtAutoselect最简单
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ComCtrls, StdCtrls, ExtCtrls, MPlayer;

type
TForm1 = class(TForm)
Button1:TButton;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
UpDown1: TUpDown;
TrackBar1: TTrackBar;
SpeedButton1: TSpeedButton;
OpenDialog1: TOpenDialog;
MdPlayer: TMediaPlayer;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure MediaPlayer1Click(Sender: TObject;
Button: TMPBtnType;
vardo
Default: Boolean);
procedure TrackBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;
fetchf:boolean;
path:string;
count:integer;

implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender:Tobject);
begin

MdPlayer.filename:='';
Trackbar1.enabled:=False;
with Mdplayerdo
begin

Form1.Caption:=filename;
path:=extractfilepath(filename)+'bmp';
count:=0;
if filename<>''then
begin

open;
trackbar1.enabled:=true;
trackbar1.min:=mdplayer.startpos;
trackbar1.max:=mdplayer.length;
trackbar1.position:=mdplayer.position;
label2.caption:='当前位置:'+inttostr(Mdplayer.position);
trackbar1.setfocus;
frames:=1;
label1.caption:='文件名:'+filename+#13#10+'总长度:'+inttostr(length);
label1.caption:=label1.caption+#13#10+'起始位置:'+inttostr(startpos);
end else
begin

label1.caption:='';
label2.caption:='';
end;

end;

end;



procedure TForm1.SpeedButton1Click(Sender: TObject);
begin

if speedbutton1.Down then
begin

fetchf:=true;
mdplayer.frames:=updown1.position
end
else
fetchf:=false;
end;




procedure TForm1.Button1Click(Sender: TObject);
begin

mdplayer.close;
trackbar1.enabled:=false;
label1.Caption:='';
label2.caption:='';
if opendialog1.execute then

begin

mdplayer.filename:=opendialog1.filename;
with mdplayerdo

begin

form1.Caption:=filename;
path:=extractfilepath(filename)+'.bmp';
count:=0;
if filename<>'' then
begin

open;
trackbar1.enabled:=true;
trackbar1.min:=mdplayer.startpos;
trackbar1.max:=mdplayer.length;
label2.caption:='当前位置:'+inttostr(mdplayer.position);
trackbar1.SetFocus;
frames:=1;
label1.Caption:='文件名:'+filename+#13#10+'总长度:'+inttostr(length);
label1.Caption:=label1.Caption+#13#10+'起始位置:'+inttostr(startpos)
end
else

begin

label1.caption:='';
label2.caption:='';
end;

end;

end;

end;


procedure TForm1.MediaPlayer1Click(Sender: TObject;
Button: TMPBtnType;
vardo
Default: Boolean);
var mybmp:tbitmap;
mycanvas:tcanvas;
dc:hdc;
rect:trect;
name,bmp:string;
begin

trackbar1.min:=mdplayer.startpos;
trackbar1.max:=mdplayer.length;
label2.caption:='当前位置:'+inttostr(mdplayer.position);
if((button=btback)or(button=btstep)) and fetchf then

try
mybmp:=tbitmap.create;
mycanvas:=tcanvas.create;
rect:=mdplayer.displayrect;
dc:=getdc(panel1.handle);
mycanvas.handle:=dc;
mybmp.width:=rect.right-rect.left;
mybmp.height:=rect.bottom-rect.top;
mybmp.canvas.copyrect(rect,mycanvas,rect);
count:=count+1;
if count<10 then
name:='000'+inttostr(count)
else
if count<100 then
name:='00'+inttostr(count)
else
if count<1000 then
name:='0'+inttostr(count);
name:=path+name+'.bmp';
mybmp.savetofile(name);
finally
releasedc(0,dc);
mybmp.free;
mycanvas.free;
end;

end;


procedure TForm1.TrackBar1Change(Sender: TObject);
begin

mdplayer.position:=trackbar1.position;
label2.caption:='当前位置:'+inttostr(mdplayer.position);

end;


end.
 
多给点分,给你解决更多问题!
 
不知到mediaplayer能不能播放.rm文件和DVD文件?
 
肯定不能,
 
唔该晒!大家!
------柳枫
 
后退
顶部