播放mp3的源代码。希望有所帮助!
//-----------------------------------------------------------------------------
// Purpose: Get The Play Item's Status
//-----------------------------------------------------------------------------
DWORD WINAPI getinfo(DWORD item,DWORD& m_count)
{
MCI_STATUS_PARMS mcistatusparms;
mcistatusparms.dwCallback=NULL;//(DWORD)GetSafeHwnd();
mcistatusparms.dwItem=item;
mcistatusparms.dwReturn=0;
mciSendCommand(m_count,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mcistatusparms);
return mcistatusparms.dwReturn;
}
//-----------------------------------------------------------------------------
// Purpose: Play Mp3 (Call It Via AfxBeginThread)
// Input : pParam - Mp3 FileName
// Output : UINT
//-----------------------------------------------------------------------------
UINT PlayMp3(LPVOID pParam)
{
MCI_OPEN_PARMS mciopenparms;
MCI_PLAY_PARMS mciplayparms;
mciopenparms.lpstrElementName= *((CString*)pParam);
mciopenparms.lpstrDeviceType=NULL;
mciopenparms.dwCallback=NULL;
MCIERROR e = mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);//マ?CIノ雎クキ「ヒヘテ・隝鋧「
DWORD m_count=mciopenparms.wDeviceID;
mciplayparms.dwCallback= NULL;//(DWORD)GetSafeHwnd();
DWORD cdlen=getinfo(MCI_STATUS_LENGTH,m_count);
DWORD cdto=MCI_MAKE_HMS(MCI_HMS_HOUR(cdlen),MCI_HMS_MINUTE(cdlen),MCI_HMS_SECOND(cdlen));
mciplayparms.dwFrom=0;
mciplayparms.dwTo=cdto;
e = mciSendCommand(mciopenparms.wDeviceID,MCI_PLAY,MCI_WAIT|MCI_TO|MCI_FROM,(DWORD)(LPVOID)& mciplayparms);
DeleteFile(mciopenparms.lpstrElementName);
SAFE_DELETE(pParam);
return 0;
}
//-----------------------------------------------------------------------------
// Purpose: Play Mp3 File
// Input : sFileName - Mp3 File Name
// Output : void WINAPI
//-----------------------------------------------------------------------------
void WINAPI PlayMp3File(CString sFileName)
{
MCI_OPEN_PARMS mciopenparms;
MCI_PLAY_PARMS mciplayparms;
mciopenparms.lpstrElementName= sFileName;
mciopenparms.lpstrDeviceType=NULL;
mciopenparms.dwCallback=NULL;
MCIERROR e = mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);
DWORD m_count=mciopenparms.wDeviceID;
mciplayparms.dwCallback= NULL;//(DWORD)GetSafeHwnd();
DWORD cdlen=getinfo(MCI_STATUS_LENGTH,m_count);
DWORD cdto=MCI_MAKE_HMS(MCI_HMS_HOUR(cdlen),MCI_HMS_MINUTE(cdlen),MCI_HMS_SECOND(cdlen));
mciplayparms.dwFrom=0;
mciplayparms.dwTo=cdto;
e = mciSendCommand(mciopenparms.wDeviceID,MCI_PLAY,MCI_TO|MCI_FROM,(DWORD)(LPVOID)& mciplayparms);
}