关于delphi的问题(50分)

  • 主题发起人 主题发起人 羽.泉
  • 开始时间 开始时间

羽.泉

Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi5编了一个很小很小的播放器,但trackbar不随着播放的进度而改变,不知为什么?请指教!!!下面是源代码:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, MPlayer, ExtCtrls, ComCtrls,unit2;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Panel1: TPanel;
TrackBar1: TTrackBar;
OpenDialog1: TOpenDialog;
Timer1: TTimer;
MediaPlayer1: TMediaPlayer;
Open1: TMenuItem;
Close1: TMenuItem;
Exit1: TMenuItem;
PopupMenu1: TPopupMenu;
Open2: TMenuItem;
Close2: TMenuItem;
Exit2: TMenuItem;
H1: TMenuItem;
procedure Open1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Open2Click(Sender: TObject);
procedure Close2Click(Sender: TObject);
procedure Exit2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure H1Click(Sender: TObject);
private
{ Private declarations}
runed:boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Open1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
mediaplayer1.FileName:=opendialog1.FileName;
mediaplayer1.Open;
runed:=true;
trackbar1.Max:=mediaplayer1.Length;
end;
end;

procedure TForm1.Close1Click(Sender: TObject);
begin
mediaplayer1.Close;
runed:=false;
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
mediaplayer1.Close;
close;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if runed then
mediaplayer1.Position:=trackbar1.Position;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
runed:=false;
end;

procedure TForm1.Open2Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
mediaplayer1.FileName:=opendialog1.FileName;
mediaplayer1.Open;
runed:=true;
trackbar1.Max:=mediaplayer1.Length;

end;
end;

procedure TForm1.Close2Click(Sender: TObject);
begin
mediaplayer1.Close;
runed:=false;
end;

procedure TForm1.Exit2Click(Sender: TObject);
begin
mediaplayer1.Close;
close;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if runed then
trackbar1.Position:=mediaplayer1.Position;
end;

procedure TForm1.H1Click(Sender: TObject);
begin
form2.showmodal;
end;

end.
如果谁会请和我联系:mydream@371.net.谢谢啦!
 
不知道!
不如用Windows Media Player 的ocx吧!
 
你没有哪条语句是让TrackBar动的呀!
你只是在响应teackbar动的事件.
 

你应该根据播放的进度来设置 position,
 
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if runed then
mediaplayer1.Position:=trackbar1.Position;
end;
在Ontimer事件到达时对trackbar改变(trackbar1.Position:=mediaplayer1.Position),然后,调用trackbar1change事件(上面的),你又对mediaplayer1的position进行了设置,mediaplay1变成了wait状态.增加一个变量posit;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if runed then
begin
posit :=MediaPlayer1.Position;
trackbar1.Position :=self.posit;
end;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if runed then
if trackbar1.position <> self.posit then
begin
MediaPlayer1.Position := trackbar1.Position;
MediaPlayer1.Play;
end;
end;
 
同意ljactive
 
来晚了一步,就是ljactive所说的
 
时间太久,强制结束。 wjiachun
 
后退
顶部