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

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "CDPlay.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TCDForm *CDForm;
  9. //---------------------------------------------------------------------------
  10. __fastcall TCDForm::TCDForm(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TCDForm::BitBtn1Click(TObject *Sender)
  16. {
  17.     MediaPlayer1->DeviceType=dtCDAudio;
  18.     //设置播放设备类型
  19.     MediaPlayer1->Open();
  20.     //打开多媒体设备
  21.   MediaPlayer1->Play();
  22.     //播放CD
  23.     Timer1->Enabled=true;
  24.     //设置组件有效状态
  25.     BitBtn1->Enabled=true;
  26.     BitBtn2->Enabled=true;
  27.     BitBtn3->Enabled=true;
  28.     BitBtn4->Enabled=true;
  29.     BitBtn5->Enabled=true;
  30.     //设置按钮有效状态
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TCDForm::Timer1Timer(TObject *Sender)
  34. {
  35.     Edit1->Text=IntToStr(MediaPlayer1->Tracks);
  36.     //显示曲目总数
  37.     Edit2->Text=IntToStr(MediaPlayer1->Position);
  38.     //显示播放位置
  39.     MediaPlayer1->TimeFormat=0;
  40.     //设置时间格式
  41.     Edit3->Text=IntToStr(MediaPlayer1->Length/60000)+"分";
  42.     //显示唱片长度
  43.     Edit4->Text=IntToStr(MediaPlayer1->Start);
  44.     //显示播放起始位置
  45.     switch (MediaPlayer1->Mode)
  46.     {
  47.         case 524: Edit5->Text="Not ready";
  48.                   break;
  49.         case 525: Edit5->Text="Stopped";
  50.                   break;
  51.         case 526: Edit5->Text="Playing";
  52.                   break;
  53.         case 527: Edit5->Text="Recording";
  54.                   break;
  55.         case 528: Edit5->Text="Seeking";
  56.                   break;
  57.         case 529: Edit5->Text="Paused";
  58.                   break;
  59.         case 530: Edit5->Text="Open";
  60.                   break;
  61.          //显示播放模式
  62.     }
  63.         
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TCDForm::BitBtn2Click(TObject *Sender)
  67. {
  68.     MediaPlayer1->Pause();
  69.     //暂停播放
  70.         
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TCDForm::BitBtn3Click(TObject *Sender)
  74. {
  75.     MediaPlayer1->Stop();
  76.     //停止播放
  77.         
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TCDForm::BitBtn4Click(TObject *Sender)
  81. {
  82.     MediaPlayer1->Next();
  83.     //跳到下一首
  84.         
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TCDForm::BitBtn5Click(TObject *Sender)
  88. {
  89.     MediaPlayer1->Previous();
  90.     //跳到前一首
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TCDForm::FormCreate(TObject *Sender)
  94. {
  95.     Timer1->Enabled=false;
  96.     //设置计时器有效状态
  97.     BitBtn1->Enabled=true;
  98.     BitBtn2->Enabled=false;
  99.     BitBtn3->Enabled=false;
  100.     BitBtn4->Enabled=false;
  101.     BitBtn5->Enabled=false;
  102.     //设置按钮有效状态
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TCDForm::BitBtn6Click(TObject *Sender)
  106. {
  107. Close();        
  108. }
  109. //---------------------------------------------------------------------------