WavePlay.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:2k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "WavePlay.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TWaveForm *WaveForm;
- //---------------------------------------------------------------------------
- __fastcall TWaveForm::TWaveForm(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TWaveForm::FormCreate(TObject *Sender)
- {
- BitBtn1->Enabled=true;
- BitBtn2->Enabled=false;
- Timer1->Enabled=false;
- //设置控件有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TWaveForm::BitBtn1Click(TObject *Sender)
- {
- OpenDialog1->Title="请选择一个声音文件:";
- //设置对话框标题
- OpenDialog1->Filter="声音文件(*.wav)|*.wav";
- //设置文件过滤器
- OpenDialog1->Execute();
- //显示对话框
- if(OpenDialog1->FileName!="")
- {
- MediaPlayer1->FileName=OpenDialog1->FileName;
- //设置文件的路径和文件名
- MediaPlayer1->Open();
- //打开多媒体设备
- ProgressBar1->Min=0;
- ProgressBar1->Max=MediaPlayer1->Length;
- //设置进度条参数
- Timer1->Enabled=true;
- BitBtn2->Enabled=true;
- //设置按钮有效状态
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWaveForm::Timer1Timer(TObject *Sender)
- {
- ProgressBar1->Enabled=true;
- ProgressBar1->Position=MediaPlayer1->Position;
- //动态显示播放进度
- }
- //---------------------------------------------------------------------------
- void __fastcall TWaveForm::BitBtn2Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------