这是一个用TScrollBar控制的简单例子,你可以参考一下,不过TTrackBar没有类似的事件。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, MPlayer;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Button1: TButton;
Timer1: TTimer;
ScrollBar1: TScrollBar;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MediaPlayer1.FileName := 'E:/01.mp3';
MediaPlayer1.Open;
ScrollBar1.Min := 0;
ScrollBar1.Max := MediaPlayer1.Length;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ScrollBar1.Position := MediaPlayer1.Position;
end;
procedure TForm1.ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
MediaPlayer1.Pause;
MediaPlayer1.Position := ScrollBar1.Position;
MediaPlayer1.Play;
end;
end.