⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 这是用C++BUILDER编写的播放声音文件的程序
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "MAINFORM.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // pop up the common file dialog
  if(OpenDialog1->Execute())
  {
    MediaPlayer1->FileName=OpenDialog1->FileName;
    // Open raises an exception if something acts up. use a try 
    // catch block to detect an error.
    try
    {
      MediaPlayer1->Open();
    }
    catch (...)
    {
     // should Application->Terminate if an exception occurs
      Application->MessageBox("Error opening file",mtWarning,MB_ICONWARNING|MB_OK);
    }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MediaPlayer1Click(TObject *Sender, TMPBtnType Button,
  bool &DoDefault)
{
  // find out which button was pressed, if Play, then start
  // the timer, if Stop the disable it. The timer will just
  // run if pause was pushed
  if(Button == btPlay)
    Timer1->Enabled = true;
  else if (Button == btStop)
    Timer1->Enabled = false;

  // set DoDefault to true so the MediaPlayer will do
  // what it normally does for the button press
  DoDefault = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  // update position using properties of TMediaPlayer need to cast because
  // TProgressBar is 16 bits while TMediaPlayer is 32. Division ensures that
  // number will be between 0 and 100
  ProgressBar1->Position = (TProgressRange)(MediaPlayer1->Position * 100 /
                                              MediaPlayer1->Length);
  // if media has finished then shut off the timer
  if(ProgressBar1->Position == 100)
    Timer1->Enabled = false;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -