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