unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MPlayer, ExtCtrls, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
OpenMbt: TButton;
PauseMbt: TButton;
PlayMbt: TButton;
StopMbt: TButton;
OpenDialog1: TOpenDialog;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
TB_vol: TTrackBar;
TB_mm: TTrackBar;
TB_r: TTrackBar;
TB_l: TTrackBar;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
procedure PlayMbtClick(Sender: TObject);
procedure StopMbtClick(Sender: TObject);
procedure OpenMbtClick(Sender: TObject);
procedure PauseMbtClick(Sender: TObject);
procedure TB_lChange(Sender: TObject);
procedure TB_rChange(Sender: TObject);
procedure TB_volChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
waveoutgetvolume(0,@vol);
TB_l.Position :=hi(vol);
TB_r.Position :=hi(vol shr 16);
TB_vol.Position:=hi(vol) or hi(vol shr 16);
TB_l.Max:=TB_vol.Position;
TB_r.Max:=TB_vol.Position;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if mediaplayer1.mode=mpplaying then
begin
tb_mm.Position:=mediaplayer1.Position;
end
else
begin
if mediaplayer1.mode=mpstopped then
stopmbtclick(self);
timer1.Enabled:=false;
end;
end;
procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
case button of
btplay :
begin
caption := 'playing';
end;
btpause:
begin
caption := 'paused';
end;
btstop:
begin
caption := 'stopped';
end;
btnext:
begin
caption := 'next';
end;
btprev:
begin
caption := 'previous';
end;
btstep:
begin
caption := 'step';
end;
btback:
begin
caption := 'back';
end;
btrecord:
begin
caption := 'record';
end;
bteject:
begin
caption := 'eject';
end;
end;
end;
procedure TForm1.PlayMbtClick(Sender: TObject);
begin
if mediaplayer1.mode=mpPaused then
begin
playmbt.Enabled:=false;
stopmbt.Enabled:=true;
pausembt.Enabled:=true;
mediaplayer1.Resume;
timer1.Enabled:=true;
end
else
begin
mediaplayer1.Open;
tb_mm.Max:=mediaplayer1.Length;
domediaopen;
mediaplayer1.Play;
timer1.Enabled:=true;
if mediaplayer1.mode<>mpplaying then
mediaplayer1.Play;
playmbt.Enabled:=false;
stopmbt.Enabled:=true;
pausembt.Enabled:=true;
end;
end;
procedure TForm1.StopMbtClick(Sender: TObject);
begin
tb_mm.Position:=0;
stopmbt.Enabled:=false;
pausembt.Enabled:=false;
playmbt.Enabled:=true;
mediaplayer1.stop;
end;
procedure TForm1.OpenMbtClick(Sender: TObject);
begin
if not opendialog1.Execute then
exit;
mediapayer1.filename:=opendialog1.filename;
dowediaopen;
playmbt.Click;
end;
procedure TForm1.PauseMbtClick(Sender: TObject);
begin
mediaplayer1.Pause;
pausembt.Enabled:=not pausembt.Enabled;
playmbt.Enabled:=not playmbt.Enabled;
end;
procedure TForm1.TB_lChange(Sender: TObject);
var
pos,vol:longint;
begin
tb_l.Max:=tb_vol.Position;
pos:=tb_l.position;
waveoutgetvolume(0,@vol);
vol:=vol and $ffff0000 or (pos shl 8);
waveoutgetvolume(0,vol);
end;
procedure TForm1.TB_rChange(Sender: TObject);
var
pos,vol:longint;
begin
tb_r.Max:=tb_vol.Position;
pos:=tb_r.position;
waveoutgetvolume(0,@vol);
vol:=vol and $0000ffff or (pos shl 24);
waveoutgetvolume(0,vol);
end;
procedure TForm1.TB_volChange(Sender: TObject);
var
pos,vol:longint;
begin
pos:=tb_vol.positions;
vol:=(pos shl 8)or(pos shl 24);
waveoutsetvolme(0,vol);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Close;
end;
end.
麻烦你留下QQ可以吗,我想和你多交流。
你也可以加我。QQ:285822027