CDPlay.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:3k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "CDPlay.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TCDForm *CDForm;
- //---------------------------------------------------------------------------
- __fastcall TCDForm::TCDForm(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn1Click(TObject *Sender)
- {
- MediaPlayer1->DeviceType=dtCDAudio;
- //设置播放设备类型
- MediaPlayer1->Open();
- //打开多媒体设备
- MediaPlayer1->Play();
- //播放CD
- Timer1->Enabled=true;
- //设置组件有效状态
- BitBtn1->Enabled=true;
- BitBtn2->Enabled=true;
- BitBtn3->Enabled=true;
- BitBtn4->Enabled=true;
- BitBtn5->Enabled=true;
- //设置按钮有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::Timer1Timer(TObject *Sender)
- {
- Edit1->Text=IntToStr(MediaPlayer1->Tracks);
- //显示曲目总数
- Edit2->Text=IntToStr(MediaPlayer1->Position);
- //显示播放位置
- MediaPlayer1->TimeFormat=0;
- //设置时间格式
- Edit3->Text=IntToStr(MediaPlayer1->Length/60000)+"分";
- //显示唱片长度
- Edit4->Text=IntToStr(MediaPlayer1->Start);
- //显示播放起始位置
- switch (MediaPlayer1->Mode)
- {
- case 524: Edit5->Text="Not ready";
- break;
- case 525: Edit5->Text="Stopped";
- break;
- case 526: Edit5->Text="Playing";
- break;
- case 527: Edit5->Text="Recording";
- break;
- case 528: Edit5->Text="Seeking";
- break;
- case 529: Edit5->Text="Paused";
- break;
- case 530: Edit5->Text="Open";
- break;
- //显示播放模式
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn2Click(TObject *Sender)
- {
- MediaPlayer1->Pause();
- //暂停播放
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn3Click(TObject *Sender)
- {
- MediaPlayer1->Stop();
- //停止播放
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn4Click(TObject *Sender)
- {
- MediaPlayer1->Next();
- //跳到下一首
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn5Click(TObject *Sender)
- {
- MediaPlayer1->Previous();
- //跳到前一首
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::FormCreate(TObject *Sender)
- {
- Timer1->Enabled=false;
- //设置计时器有效状态
- BitBtn1->Enabled=true;
- BitBtn2->Enabled=false;
- BitBtn3->Enabled=false;
- BitBtn4->Enabled=false;
- BitBtn5->Enabled=false;
- //设置按钮有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TCDForm::BitBtn6Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------