Unit1.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:4k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "MPEGPLAYLib_OCX"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- OpenDialog1->Title="请选择一个音乐文件:";
- //设置对话框标题
- OpenDialog1->DefaultExt="mp3";
- //设置缺省扩展名
- OpenDialog1->Filter="All Files(*.*)|*.*|MP3 Files(*.mp3)|*.mp3";
- //设置文件过滤器
- Edit1->Enabled=false;
- Edit2->Enabled=false;
- Edit3->Enabled=false;
- Edit4->Enabled=false;
- //设置文本框有效状态
- Edit1->Text="";
- Edit2->Text="";
- Edit3->Text="";
- Edit4->Text="";
- //设置文本框显示文本
- Button2->Enabled=false;
- Button3->Enabled=false;
- Button4->Enabled=false;
- Button5->Enabled=false;
- //设置按钮有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- WideString Mp3File;
- OpenDialog1->Execute();
- //显示对话框
- Edit1->Text=OpenDialog1->FileName;
- Mp3File=OpenDialog1->FileName;
- if(OpenDialog1->FileName!="")
- {
- Mp3Play1->Open(Mp3File,NULL);
- //打开指定的MP3文件
- Button2->Enabled=true;
- Button3->Enabled=false;
- Button4->Enabled=false;
- Button5->Enabled=false;
- //设置按钮有效状态
- Edit2->Text=IntToStr(Mp3Play1->TotalTime);
- Edit3->Text=IntToStr(Mp3Play1->GetVolumeLeft());
- Edit4->Text=IntToStr(Mp3Play1->GetVolumeRight());
- //设置文本框显示文本
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton1Click(TObject *Sender)
- {
- Edit3->Enabled=false;
- Edit4->Enabled=false;
- //设置文本框有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton2Click(TObject *Sender)
- {
- Edit3->Enabled=true;
- Edit4->Enabled=true;
- //设置文本框有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)
- {
- Mp3Play1->SetVolume(StrToInt(Edit3->Text),StrToInt(Edit4->Text));
- //设置播放音乐的音量
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Edit4KeyPress(TObject *Sender, char &Key)
- {
- Mp3Play1->SetVolume(StrToInt(Edit3->Text),StrToInt(Edit4->Text));
- //设置播放音乐的音量
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Mp3Play1->Play();
- //播放指定的音乐文件
- Button3->Enabled=true;
- Button4->Enabled=true;
- Button5->Enabled=true;
- //设置按钮有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- Mp3Play1->Pause();
- //暂停播放音乐
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- Mp3Play1->Stop();
- //停止播放音乐
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- Mp3Play1->Close();
- //关闭MP3播放器
- Button2->Enabled=false;
- Button3->Enabled=false;
- Button4->Enabled=false;
- Button5->Enabled=false;
- //设置按钮有效状态
- Edit1->Text="";
- Edit2->Text="";
- //设置文本框显示文本
- }
- //---------------------------------------------------------------------------