B
basinjp
Unregistered / Unconfirmed
GUEST, unregistred user!
unit medieplay429;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, Menus, MPlayer, Buttons, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
FMenu: TMenuItem;
OMenu: TMenuItem;
CMenu: TMenuItem;
N4: TMenuItem;
EMenu: TMenuItem;
DMenu: TMenuItem;
VMenu: TMenuItem;
WMenu: TMenuItem;
MMenu: TMenuItem;
RMenu: TMenuItem;
TMenu: TMenuItem;
FrameMenu: TMenuItem;
MediaPlayer1: TMediaPlayer;
TrackBar1: TTrackBar;
SBPlay: TSpeedButton;
SBStop: TSpeedButton;
SBPause: TSpeedButton;
SBopen: TSpeedButton;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
OpenDialog1: TOpenDialog;
procedure OMenuClick(Sender: TObject);
procedure CMenuClick(Sender: TObject);
procedure EMenuClick(Sender: TObject);
procedure VMenuClick(Sender: TObject);
procedure WMenuClick(Sender: TObject);
procedure MMenuClick(Sender: TObject);
procedure TMenuClick(Sender: TObject);
procedure FrameMenuClick(Sender: TObject);
procedure SBPlayClick(Sender: TObject);
procedure SBStopClick(Sender: TObject);
procedure SBPauseClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure MediaPlayer1Notify(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure SetButton (tag:boolean);
function ZeroFill (size:integer;s:string):string;
procedure OpenMedia;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SetButton(tag:boolean);
begin
CMenu.Enabled:=tag;
TMenu.Enabled:=tag;
Framemenu.Enable:=tag;
TrackBar1.Enabled:=tag;
SBPlay.Enabled:=tag;
Timer1.Enabled:=tag;
end;
function TForm1.ZeroFill(size:integer;s:string):string;
var
a,b:integer;
t:string;
begin
SetLength(t,size);
for a:=1 to sizedo
t[a]:='0';
b:=size;
for a:=length(s)do
wnto 1do
begin
t:=s[a];
dec(b);
end;
ZeroFill:=t;
end;
procedure TForm1.Openmedia;
begin
with MediaPlayer1do
begin
Close;
try
Open;
TimeFormat:=tfMilliSeconds;
Trackbar1.Min:=0;
{毫秒为单位的数值改为以秒为单位}
Trackbar1.Max:=Length div 1000;
SetButton(True);
except
MessageDlg('不能播放的文件!',mtError,[mbOK],0);
SetButton(False);
end;
end;
end;
procedure TForm1.OMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=4;
if Opendialog1.Execute then
begin
with MediaPlayer1do
begin
DeviceType:=dtAutoSelect;
FileName:=OpenDialog1.FileName;
end;
OpenMedia;//显示文件的总时间长度
Label2.Caption:=inttostr(Trackbar1.Max);
//显示文件的一半长度
Label3.Caption:=inttostr(Trackbar1.Max div 2);
end;
end;
procedure TForm1.CMenuClick(Sender: TObject);
begin
label2.caption:='';
label3.Caption:='';
mediaplayer1.Close;
setbutton(false);
end;
procedure TForm1.EMenuClick(Sender: TObject);
begin
mediaplayer1.Close;
close;
end;
procedure TForm1.VMenuClick(Sender: TObject);
begin
opendialog1.FilterIndex:=1;
if opendialog1.Execute then
begin
with mediaplayer1do
begin
devicetype:=dtavivideo;
filename:=opendialog1.filename;
end;
openmedia;
label2.Caption:=inttostr(trackbar1.Max);
label3.Caption:=inttostr(trackbar1.Max div 2);
end;
end;
procedure TForm1.WMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=2;
if OpenDialog1.Execute then
begin
with MediaPlayer1do
begin
FileName:=OpenDialog1.FileName;
end;
openmedia;
label2.Caption:=inttostr(TrackBar1.Max);
label3.Caption:=inttostr(TrackBar1.Max div 2);
end;
end;
procedure TForm1.MMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=3;
if OpenDialog1.Execute then
begin
with MediaPlayer1do
begin
FileName:=OpenDialog1.FileName;
end;
openmedia;
label2.Caption:=inttostr(TrackBar1.Max);
label3.Caption:=inttostr(TrackBar1.Max div 2);
end;
end;
procedure TForm1.TMenuClick(Sender: TObject);
begin
TMenu.Checked:=true;
FrameMenu.Checked:=false;
with MediaPlayer1do
begin
TimeFormat:=tfMilliSeconds;
TrackBar1.Max:=Length div 1000;
Trackbar1.Position:=Position div 1000;
Label2.Caption:=inttostr(Length div 1000);
Label3.Caption:=inttostr(Length div 2000);
end;
end;
procedure TForm1.FrameMenuClick(Sender: TObject);
begin
TMenu.Checked:=false;
FrameMenu.Checked:=true;
with MediaPlayer1do
begin
TimeFormat:=tfFrames;
TrackBar1.Max:=Length;
TrackBar1.Position:=Position;
Label2.Caption:=inttostr(Length);
Label3.Caption:=inttostr(Length div 2);
end;
end;
procedure TForm1.SBPlayClick(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPaused then
MediaPlayer1.Resume
else
MediaPlayer1.play;
SBPlay.Enabled:=false;
SBPause.Enabled:=true;
SBStop.Enabled:=true;
if not Timer1.Enabled then
Timer1.Enabled:=true;
end;
procedure TForm1.SBStopClick(Sender: TObject);
begin
MediaPlayer1.Stop;
TrackBar1.Position:=0;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
Timer1.Enabled:=false;
end;
procedure TForm1.SBPauseClick(Sender: TObject);
begin
MediaPlayer1.Pause;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
Timer1.Enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPlaying then
if TMenu.Checked then
begin
TrackBar1.Position:=MediaPlayer1.Position div 1000;
Label4.Caption:=ZeroFill(2,inttostr(TrackBar1.Position div 60))
+':'+ZeroFill(2,inttostr(TrackBar1.Position mod 60))+'(分钟:秒)'
end
else
begin
TrackBar1.Position:=MediaPlayer1.Position;
Label4.Caption:=inttostr(MediaPlayer1.Position)+'(帧)';
end;
end;
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if mediaplayer1.Mode=mpStopped then
begin
MediaPlayer1.Rewind;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
TrackBar1.Position:=0;
end;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPlaying then
begin
MediaPlayer1.Pause;
if TMenu.Checked then
MediaPlayer1.Position:=TrackBar1.Position*1000
else
MediaPlayer1.Position:=TrackBar1.Position;
MediaPlayer1.Resume;
end
else
begin
if TMenu.Checked then
MediaPlayer1.Position:=TrackBar1.Position*1000
else
MediaPlayer1.Position:=TrackBar1.Position;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tmenu.Checked:=true;
SBPlay.Enabled:=false;
SBStop.Enabled:=false;
SBPause.Enabled:=false;
setButton(False);
end;
end.
运行以后出现[Error] medieplay429.pas(71): Undeclared identifier: 'Enable'
怎么也找不出错误,希望高手指点
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, Menus, MPlayer, Buttons, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
FMenu: TMenuItem;
OMenu: TMenuItem;
CMenu: TMenuItem;
N4: TMenuItem;
EMenu: TMenuItem;
DMenu: TMenuItem;
VMenu: TMenuItem;
WMenu: TMenuItem;
MMenu: TMenuItem;
RMenu: TMenuItem;
TMenu: TMenuItem;
FrameMenu: TMenuItem;
MediaPlayer1: TMediaPlayer;
TrackBar1: TTrackBar;
SBPlay: TSpeedButton;
SBStop: TSpeedButton;
SBPause: TSpeedButton;
SBopen: TSpeedButton;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
OpenDialog1: TOpenDialog;
procedure OMenuClick(Sender: TObject);
procedure CMenuClick(Sender: TObject);
procedure EMenuClick(Sender: TObject);
procedure VMenuClick(Sender: TObject);
procedure WMenuClick(Sender: TObject);
procedure MMenuClick(Sender: TObject);
procedure TMenuClick(Sender: TObject);
procedure FrameMenuClick(Sender: TObject);
procedure SBPlayClick(Sender: TObject);
procedure SBStopClick(Sender: TObject);
procedure SBPauseClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure MediaPlayer1Notify(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure SetButton (tag:boolean);
function ZeroFill (size:integer;s:string):string;
procedure OpenMedia;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SetButton(tag:boolean);
begin
CMenu.Enabled:=tag;
TMenu.Enabled:=tag;
Framemenu.Enable:=tag;
TrackBar1.Enabled:=tag;
SBPlay.Enabled:=tag;
Timer1.Enabled:=tag;
end;
function TForm1.ZeroFill(size:integer;s:string):string;
var
a,b:integer;
t:string;
begin
SetLength(t,size);
for a:=1 to sizedo
t[a]:='0';
b:=size;
for a:=length(s)do
wnto 1do
begin
t:=s[a];
dec(b);
end;
ZeroFill:=t;
end;
procedure TForm1.Openmedia;
begin
with MediaPlayer1do
begin
Close;
try
Open;
TimeFormat:=tfMilliSeconds;
Trackbar1.Min:=0;
{毫秒为单位的数值改为以秒为单位}
Trackbar1.Max:=Length div 1000;
SetButton(True);
except
MessageDlg('不能播放的文件!',mtError,[mbOK],0);
SetButton(False);
end;
end;
end;
procedure TForm1.OMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=4;
if Opendialog1.Execute then
begin
with MediaPlayer1do
begin
DeviceType:=dtAutoSelect;
FileName:=OpenDialog1.FileName;
end;
OpenMedia;//显示文件的总时间长度
Label2.Caption:=inttostr(Trackbar1.Max);
//显示文件的一半长度
Label3.Caption:=inttostr(Trackbar1.Max div 2);
end;
end;
procedure TForm1.CMenuClick(Sender: TObject);
begin
label2.caption:='';
label3.Caption:='';
mediaplayer1.Close;
setbutton(false);
end;
procedure TForm1.EMenuClick(Sender: TObject);
begin
mediaplayer1.Close;
close;
end;
procedure TForm1.VMenuClick(Sender: TObject);
begin
opendialog1.FilterIndex:=1;
if opendialog1.Execute then
begin
with mediaplayer1do
begin
devicetype:=dtavivideo;
filename:=opendialog1.filename;
end;
openmedia;
label2.Caption:=inttostr(trackbar1.Max);
label3.Caption:=inttostr(trackbar1.Max div 2);
end;
end;
procedure TForm1.WMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=2;
if OpenDialog1.Execute then
begin
with MediaPlayer1do
begin
FileName:=OpenDialog1.FileName;
end;
openmedia;
label2.Caption:=inttostr(TrackBar1.Max);
label3.Caption:=inttostr(TrackBar1.Max div 2);
end;
end;
procedure TForm1.MMenuClick(Sender: TObject);
begin
OpenDialog1.FilterIndex:=3;
if OpenDialog1.Execute then
begin
with MediaPlayer1do
begin
FileName:=OpenDialog1.FileName;
end;
openmedia;
label2.Caption:=inttostr(TrackBar1.Max);
label3.Caption:=inttostr(TrackBar1.Max div 2);
end;
end;
procedure TForm1.TMenuClick(Sender: TObject);
begin
TMenu.Checked:=true;
FrameMenu.Checked:=false;
with MediaPlayer1do
begin
TimeFormat:=tfMilliSeconds;
TrackBar1.Max:=Length div 1000;
Trackbar1.Position:=Position div 1000;
Label2.Caption:=inttostr(Length div 1000);
Label3.Caption:=inttostr(Length div 2000);
end;
end;
procedure TForm1.FrameMenuClick(Sender: TObject);
begin
TMenu.Checked:=false;
FrameMenu.Checked:=true;
with MediaPlayer1do
begin
TimeFormat:=tfFrames;
TrackBar1.Max:=Length;
TrackBar1.Position:=Position;
Label2.Caption:=inttostr(Length);
Label3.Caption:=inttostr(Length div 2);
end;
end;
procedure TForm1.SBPlayClick(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPaused then
MediaPlayer1.Resume
else
MediaPlayer1.play;
SBPlay.Enabled:=false;
SBPause.Enabled:=true;
SBStop.Enabled:=true;
if not Timer1.Enabled then
Timer1.Enabled:=true;
end;
procedure TForm1.SBStopClick(Sender: TObject);
begin
MediaPlayer1.Stop;
TrackBar1.Position:=0;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
Timer1.Enabled:=false;
end;
procedure TForm1.SBPauseClick(Sender: TObject);
begin
MediaPlayer1.Pause;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
Timer1.Enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPlaying then
if TMenu.Checked then
begin
TrackBar1.Position:=MediaPlayer1.Position div 1000;
Label4.Caption:=ZeroFill(2,inttostr(TrackBar1.Position div 60))
+':'+ZeroFill(2,inttostr(TrackBar1.Position mod 60))+'(分钟:秒)'
end
else
begin
TrackBar1.Position:=MediaPlayer1.Position;
Label4.Caption:=inttostr(MediaPlayer1.Position)+'(帧)';
end;
end;
procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if mediaplayer1.Mode=mpStopped then
begin
MediaPlayer1.Rewind;
SBPlay.Enabled:=true;
SBPause.Enabled:=false;
SBStop.Enabled:=false;
TrackBar1.Position:=0;
end;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if MediaPlayer1.Mode=mpPlaying then
begin
MediaPlayer1.Pause;
if TMenu.Checked then
MediaPlayer1.Position:=TrackBar1.Position*1000
else
MediaPlayer1.Position:=TrackBar1.Position;
MediaPlayer1.Resume;
end
else
begin
if TMenu.Checked then
MediaPlayer1.Position:=TrackBar1.Position*1000
else
MediaPlayer1.Position:=TrackBar1.Position;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tmenu.Checked:=true;
SBPlay.Enabled:=false;
SBStop.Enabled:=false;
SBPause.Enabled:=false;
setButton(False);
end;
end.
运行以后出现[Error] medieplay429.pas(71): Undeclared identifier: 'Enable'
怎么也找不出错误,希望高手指点