B
basinjp
Unregistered / Unconfirmed
GUEST, unregistred user!
在mediaplayer中如何能加入快进和倒退的功能??我程序如下:
unit medieplay429;
interface
uses
Windows,MMSystem, 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;
N1: TMenuItem;
ontopbutton: TMenuItem;
MMxianshi: TMenuItem;
N3: TMenuItem;
SBRewind: TSpeedButton;
TrackBar2: TTrackBar;
TrackBar3: TTrackBar;
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);
procedure ontopbuttonClick(Sender: TObject);
procedure MMxianshiClick(Sender: TObject);
procedure SBRewindClick(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
procedure TrackBar3Change(Sender: TObject);
private
{ Private declarations }
procedure SetButton (tag:boolean);
function ZeroFill (size:integer;s:string):string;
procedure OpenMedia;
public
procedure MMNotify (var Message:TMessage);
message MM_MCINOTIFY;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SetButton(tag:boolean);
begin
CMenu.Enabled:=tag;
TMenu.Enabled:=tag;
Framemenu.Enabled:=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:=1;
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);
{begin
//显示声音播放条目
winexec('rundll32.exe shell32.dll,control_rundll access.cpl,,2',sw_shownormal);
end;
}
end;
procedure TForm1.ontopbuttonClick(Sender: TObject);
begin
if ontopbutton.Enabled=true then
begin
setwindowpos(Application.handle,hWnd_topmost,
0,0,0,0,SWP_NOMOVE+SWP_NOSIZE);
end else
begin
setwindowpos(Application.handle,hWnd_Notopmost,
0,0,0,0,SWP_NOMOVE+SWP_NOSIZE);
end;
end;
procedure TForm1.MMxianshiClick(Sender: TObject);
begin
mciSendstring('open G:/短片/文明.avi alias film',nil,0,0);
mciSendstring('window film handle 0',nil,0,0);
mciSendstring('window film state show maximized',nil,0,0);
mciSendstring('play film notify',nil,0,form1.handle);
end;
procedure TForm1.MMnotify(var message:TMessage);
begin
mciSendString('close film',nil,0,0);
end;
procedure TForm1.SBRewindClick(Sender: TObject);
begin
MediaPlayer1.Rewind;
MediaPlayer1.Play;
SBPlay.Enabled:=false;
SBPause.Enabled:=true;
SBRewind.Enabled:=true;
SBStop.Enabled:=true;
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
var t,v:longint;
begin
t:=trackbar2.position;
waveoutgetvolume(0,@v);
v:=v and $ffff0000 or (t shl 8);
waveoutsetvolume(0,v);
end;
procedure TForm1.TrackBar3Change(Sender: TObject);
var t,v:longint;
begin
t:=trackbar3.position;
waveoutgetvolume(0,@v);
v:=v and $0000ffff or (t shl 24);
waveoutsetvolume(0,v);
end;
{procedure TForm1.FormCreate (sender:tobject);
var v:longint;
begin
SBPlay.Enabled:=false;
SBPause.Enabled:=false;
SBRewind.Enabled:=false;
SBStop.Enabled:=false;
waveoutgetvolume(0,@v);
trackbar2.position :=hi(v);
trackbar3.position :=hi(v shr 16);
end;
}
end.
unit medieplay429;
interface
uses
Windows,MMSystem, 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;
N1: TMenuItem;
ontopbutton: TMenuItem;
MMxianshi: TMenuItem;
N3: TMenuItem;
SBRewind: TSpeedButton;
TrackBar2: TTrackBar;
TrackBar3: TTrackBar;
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);
procedure ontopbuttonClick(Sender: TObject);
procedure MMxianshiClick(Sender: TObject);
procedure SBRewindClick(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
procedure TrackBar3Change(Sender: TObject);
private
{ Private declarations }
procedure SetButton (tag:boolean);
function ZeroFill (size:integer;s:string):string;
procedure OpenMedia;
public
procedure MMNotify (var Message:TMessage);
message MM_MCINOTIFY;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SetButton(tag:boolean);
begin
CMenu.Enabled:=tag;
TMenu.Enabled:=tag;
Framemenu.Enabled:=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:=1;
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);
{begin
//显示声音播放条目
winexec('rundll32.exe shell32.dll,control_rundll access.cpl,,2',sw_shownormal);
end;
}
end;
procedure TForm1.ontopbuttonClick(Sender: TObject);
begin
if ontopbutton.Enabled=true then
begin
setwindowpos(Application.handle,hWnd_topmost,
0,0,0,0,SWP_NOMOVE+SWP_NOSIZE);
end else
begin
setwindowpos(Application.handle,hWnd_Notopmost,
0,0,0,0,SWP_NOMOVE+SWP_NOSIZE);
end;
end;
procedure TForm1.MMxianshiClick(Sender: TObject);
begin
mciSendstring('open G:/短片/文明.avi alias film',nil,0,0);
mciSendstring('window film handle 0',nil,0,0);
mciSendstring('window film state show maximized',nil,0,0);
mciSendstring('play film notify',nil,0,form1.handle);
end;
procedure TForm1.MMnotify(var message:TMessage);
begin
mciSendString('close film',nil,0,0);
end;
procedure TForm1.SBRewindClick(Sender: TObject);
begin
MediaPlayer1.Rewind;
MediaPlayer1.Play;
SBPlay.Enabled:=false;
SBPause.Enabled:=true;
SBRewind.Enabled:=true;
SBStop.Enabled:=true;
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
var t,v:longint;
begin
t:=trackbar2.position;
waveoutgetvolume(0,@v);
v:=v and $ffff0000 or (t shl 8);
waveoutsetvolume(0,v);
end;
procedure TForm1.TrackBar3Change(Sender: TObject);
var t,v:longint;
begin
t:=trackbar3.position;
waveoutgetvolume(0,@v);
v:=v and $0000ffff or (t shl 24);
waveoutsetvolume(0,v);
end;
{procedure TForm1.FormCreate (sender:tobject);
var v:longint;
begin
SBPlay.Enabled:=false;
SBPause.Enabled:=false;
SBRewind.Enabled:=false;
SBStop.Enabled:=false;
waveoutgetvolume(0,@v);
trackbar2.position :=hi(v);
trackbar3.position :=hi(v shr 16);
end;
}
end.