1.前言
---- mp3因其较高的压缩率,较好的音质,成为越来越多的使用者的喜爱,用自己编制的mp3播放器听mp3音乐一定很有乐趣.我以下介绍一个用delphi编制的简单mp3播放器,因为mp3音乐的解码比较复杂,普通的程序员很难编制其解码程序,但不要紧,我们可以用别人写好的解码程序来完成我们的
程序.
---- 2.设计构思
---- 我们使用mpegdll.dll来解码(很多国产的mp3播放器都用它),mpegdll.dll的作者提供了它的delphi的控件,在各大delphi网站都有下载,或在作者的主页http://www.ig.com.ua/wabbit/programs/workshop.html
下载之后,我们安装控件(必须delphi3.0以上),在component中选择install component,安装控件包中的mpegplayer.dcu,安装完成后在控件栏里多出一个add-ons来,控件就在里面.
---- 介绍一下用到的参数
mpeg.streamname 所要播放的文件名
mpeg.length 文件程度
mpeg.bitrate 压缩位率
mpeg.frequency 压缩频率
mpeg.layer 压缩层次
mpeg.mode 压缩模式
mpeg.pathtodll dll文件的路径
---- 新建一个from,放入6个label,5个button,1个checkbox,1个mpeg,1个time,1个trackbar,1个opendialog控件调整为适当的布局,点击opendialog1使*.mp3成为打开文件的后缀名.调整5个button,把其属性name改为 openbutton,pausebutton,stopbutton,playbutton和exitbutton,并把caption改为播放,暂停,停止,打开,和退出. 使3个label的caption成为,压缩位率,压缩频率,压缩层次,调整其他3个label使label4对应label1,label5对应label2,label6对应label3 caption为空,autosize为true,trackbar的tickstyle设为tsNone,chickbox的caption设为循环播放,timer的ontimer设为timer1timer
---- 3.
程序清单如下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
ExtCtrls, MPEGPlayer,Gauges,
ComCtrls,Mask, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
openButton: TButton;
playButton: TButton;
pauseButton: TButton;
stopButton: TButton;
exitButton: TButton;
CheckBox1: TCheckBox;
TrackBar1: TTrackBar;
MPEG: TMPEGPlayer;
Timer1: TTimer;
OpenDialog1: TOpenDialog;
Label6: TLabel;
procedure exitButtonClick(Sender: TObject);
procedure openButtonClick(Sender: TObject);
procedure playButtonClick(Sender: TObject);
procedure pauseButtonClick(Sender: TObject);
procedure stopButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender:
TObject; var Action: TCloseAction);
private
{ Private declarations }
dontseek:boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.exitButtonClick(Sender: TObject);
begin
close;
end;
procedure TForm1.openButtonClick(Sender: TObject);
var s:string;
begin
if not opendialog1.execute then exit;
mpeg.autoplay:=false;
mpeg.streamname:=opendialog1.filename;
mpeg.open;
trackbar1.Max:=mpeg.length;
trackbar1.position:=0;
str(trackbar1.max,s);
playbutton.Enabled:=true;
stopbutton.enabled:=true;
pausebutton.Enabled:=true;
end;
procedure TForm1.playButtonClick(Sender: TObject);
var a,b,c:string;
begin
playbutton.Enabled:=false;
openbutton.Enabled:=false;
mpeg.Play;
str(mpeg.Bitrate,a);
label4.C