//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include <mmsystem.h>
#include "MAINFORM.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Screen->Cursor = crHourGlass; // loading can be slow, change cursor
MediaPlayer1->FileName = ""; // use null string when opening CDs
MediaPlayer1->Wait = true; // wait before moving on
try
{
MediaPlayer1->Open(); // open the CD
}
catch (...)
{
// should terminate app using Application->Terminate
Application->MessageBox("Error opening compact disc",mtWarning,MB_OK);
}
Screen->Cursor = crArrow; // and restore the cursor
// check that a disc is in the drive
if (!CheckForDisc())
{
Application->MessageBox("No disc in CD-ROM drive.\n"
"Insert disc and push Open again",
"ERROR",MB_OK);
MediaPlayer1->Close();
}
else
{
UpdateCDInfo(); // update static information about cd,
Timer1->Enabled = True; // turn on the timer that will track the CD
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// check that the CD was not ejected by the user. if it was,
// set all captions to zeroes, shut of the timer, close the
// media player
if (!CheckForDisc())
{
Timer1->Enabled = false;
MediaPlayer1->Close();
TrackNumber ->Caption = "0";
TrackLength ->Caption = "00:00";
TrackTime ->Caption = "00:00";
TrackCount ->Caption = "0";
TotalTime ->Caption = "00:00";
CDTime ->Caption = "00:00";
}
else // CD was not ejected, update information
{
UpdateTrackInfo();
UpdatePositions();
}
}
//---------------------------------------------------------------------------
void TForm1::UpdateCDInfo(void)
{
// this function updates the static information on a CD.
// number of tracks and total length of the CD.
// put the media player into track mode (tracks, minutes, seconds)
// this is the normal mode for a CD player
MediaPlayer1->TimeFormat = tfTMSF;
int CDTrackCount = MediaPlayer1->Tracks; // track count
// get length of media. Length does not use TMSF mode due to
// the MCI functions it encapsulates. result is in MSF format
// use MCI_MSF macros from MMSYSTEM.H to decode Length
int CDLengthMinutes = MCI_MSF_MINUTE(MediaPlayer1->Length);
int CDLengthSeconds = MCI_MSF_SECOND(MediaPlayer1->Length);
TrackCount->Caption = IntToStr(CDTrackCount);
TotalTime->Caption = IntToStr(CDLengthMinutes) + ":" +
IntToStr(CDLengthSeconds/10) +
IntToStr(CDLengthSeconds%10);
}
void TForm1::UpdateTrackInfo(void)
{
// make sure media player is in track mode (tracks, minutes, seconds)
MediaPlayer1->TimeFormat = tfTMSF;
int TrackIndex = MCI_TMSF_TRACK(MediaPlayer1->Position); // get track number
// has the track number changed since last time, if so, update the
// static information about the song. if not, then don't bother.
if(CurrentTrack != TrackIndex)
{
CurrentTrack = TrackIndex; // update indexing variable
// just like Length, TrackLength will not use TMSF format due to the
// underlying MCI function, interpret results using MSF format.
int LengthValue = MediaPlayer1->TrackLength[TrackIndex];
int LengthMinutes = MCI_MSF_MINUTE(LengthValue); // decode return value
int LengthSeconds = MCI_MSF_SECOND(LengthValue); // using macros
TrackNumber->Caption = IntToStr(TrackIndex); // update captions
TrackLength->Caption = IntToStr(LengthMinutes) + ":" +
IntToStr(LengthSeconds/10)+ // display leading 0
IntToStr(LengthSeconds%10);
}
}
void TForm1::UpdatePositions(void)
{
// this function updates the dynamic position values for a track.
// and the entire CD.
// ensure track mode (TMSF). this way, Position will return
// values relative to the position in the current track.
MediaPlayer1->TimeFormat = tfTMSF;
int PositionValue = MediaPlayer1->Position; // get position DWord
int TPositionMinutes= MCI_TMSF_MINUTE(PositionValue); // decode result
int TPositionSeconds= MCI_TMSF_SECOND(PositionValue); // using macros
TrackTime->Caption = IntToStr(TPositionMinutes) + ":" +
IntToStr(TPositionSeconds/10) +
IntToStr(TPositionSeconds%10);
// now get out of track mode and check Position again. this time
// it will read relative to the beginning of the CD
MediaPlayer1->TimeFormat = tfMSF;
PositionValue = MediaPlayer1->Position;
int CDLengthMinutes = MCI_MSF_MINUTE(PositionValue);
int CDLengthSeconds = MCI_MSF_SECOND(PositionValue);
CDTime->Caption = IntToStr(CDLengthMinutes) + ":" +
IntToStr(CDLengthSeconds/10) +
IntToStr(CDLengthSeconds%10);
// return to track mode, media player buttons don't work right
// if we are not in track mode
MediaPlayer1->TimeFormat = tfTMSF;
}
bool TForm1::CheckForDisc(void)
{
// use MCI api function to check that a CD is present
MCI_STATUS_PARMS Status;
Status.dwItem = MCI_STATUS_MEDIA_PRESENT;
mciSendCommand(MediaPlayer1->DeviceID,
MCI_STATUS,
MCI_STATUS_ITEM|MCI_WAIT,
(DWORD) (LPMCI_STATUS_PARMS) &Status);
return (bool)Status.dwReturn;
}
cd-player.rar_player
版权申诉
49 浏览量
2022-09-20
14:16:03
上传
评论
收藏 30KB RAR 举报
局外狗
- 粉丝: 68
- 资源: 1万+
最新资源
- 办公效率:PDF-图片互转工具
- 一天的风格化规范化当时法国是
- 编译原理:正规式转NFA(有穷自动机)
- 通过 Navicat 备份文件读取连接信息和解析密码
- Linux下开箱即用的C++单元测试demo示例,public成员函数单元测试
- 连接Redis服务器 在使用Redis之前,首先需要使用redis-cli工具连接到Redis服务器 redis-cli是Re
- 连接Redis服务器 在使用Redis之前,首先需要使用redis-cli工具连接到Redis服务器 redis-cli是Red
- 连接Redis服务器 在使用Redis之前,首先需要使用redis-cli工具连接到Redis服务器 redis-cli是Red
- redis命令实践 详细教程
- redis命令实践 详细教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈