WavePlay.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:2k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WavePlay.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TWaveForm *WaveForm;
  9. //---------------------------------------------------------------------------
  10. __fastcall TWaveForm::TWaveForm(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TWaveForm::FormCreate(TObject *Sender)
  16. {
  17.     BitBtn1->Enabled=true;
  18.     BitBtn2->Enabled=false;
  19.     Timer1->Enabled=false;
  20.     //设置控件有效状态
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TWaveForm::BitBtn1Click(TObject *Sender)
  24. {
  25.     OpenDialog1->Title="请选择一个声音文件:";
  26.     //设置对话框标题
  27.     OpenDialog1->Filter="声音文件(*.wav)|*.wav";
  28.     //设置文件过滤器
  29.     OpenDialog1->Execute();
  30.     //显示对话框
  31.     if(OpenDialog1->FileName!="")
  32.     {
  33.         MediaPlayer1->FileName=OpenDialog1->FileName;
  34.         //设置文件的路径和文件名
  35.         MediaPlayer1->Open();
  36.         //打开多媒体设备
  37.     ProgressBar1->Min=0;
  38.     ProgressBar1->Max=MediaPlayer1->Length;
  39.     //设置进度条参数
  40.         Timer1->Enabled=true;
  41.         BitBtn2->Enabled=true;
  42.         //设置按钮有效状态
  43.     }
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TWaveForm::Timer1Timer(TObject *Sender)
  47. {
  48.     ProgressBar1->Enabled=true;
  49.     ProgressBar1->Position=MediaPlayer1->Position;
  50.     //动态显示播放进度
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TWaveForm::BitBtn2Click(TObject *Sender)
  54. {
  55. Close();        
  56. }
  57. //---------------------------------------------------------------------------