CSDN博客

img langzi84

VC实现的avi,mid,mp3,asf,wma播放器核心代码

发表于2004/10/17 22:18:00  4754人阅读

分类: VC++

void MediaPlayerDlg::Play(CString psing)
{
  
  extname=getExt(psing);
  if(extname=="jpg"|extname=="bmp"|extname=="gif")
  {
   
   pApp->OpenDocumentFile(psing);
   
   playing=TRUE;
  }
  else
  {
   
  
  m_pParent->ShowWindow(SW_HIDE);
  mciopenparms.lpstrElementName=psing;
  mciopenparms.lpstrDeviceType=NULL;
  mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);
  m_count=mciopenparms.wDeviceID;
  mciplayparms.dwCallback=(DWORD)GetSafeHwnd(); 
  cdlen=getinfo(MCI_STATUS_LENGTH);                                                                                                                                                                                                                                             
  if(playing==TRUE)cdfrom=MCI_MAKE_HMS(0,0,0);
  cdto=MCI_MAKE_HMS(MCI_HMS_HOUR(cdlen),MCI_HMS_MINUTE(cdlen),MCI_HMS_SECOND(cdlen)); 
  mciplayparms.dwFrom=cdfrom;
  mciplayparms.dwTo=cdto;
  mciSendCommand(m_count,MCI_PLAY,MCI_TO|MCI_FROM,(DWORD)(LPVOID)& mciplayparms);
  SetTimer(0,1000,NULL);
  m_slider.SetRange(0,cdlen);
  playing=TRUE;
  
  //计算歌曲播放时间
  second=cdlen/1000;
  
  minite=second/60;
  second=second%60;
  singtime.Format("%02d:%02d",minite,second);
  }

}
DWORD MediaPlayerDlg::getinfo(DWORD item)
{
 
 mcistatusparms.dwCallback=(DWORD)GetSafeHwnd();
 mcistatusparms.dwItem=item;
 mcistatusparms.dwReturn=0;
 mciSendCommand(m_count,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mcistatusparms);
 return mcistatusparms.dwReturn;
}

void MediaPlayerDlg::OnButtonpause()
{
 // TODO: Add your control notification handler code here
 KillTimer(0);
 DWORD dwsf=getinfo(MCI_STATUS_POSITION);
 cdfrom=MCI_MAKE_MSF(MCI_MSF_MINUTE(dwsf),MCI_MSF_SECOND(dwsf),MCI_MSF_FRAME(dwsf));
 mciSendCommand(m_count,MCI_CLOSE,0,NULL);
 m_count=0;
 playing=FALSE;

}

阅读全文
0 0

相关文章推荐

img
取 消
img