int fi,fr;
    DWORD cdfrom,cdto;
    int hour,minute,second;
    DWORD cdlen;
    DWORD getinfo(DWORD item);
    DWORD m_count;

// play a segment WAVE
void CAudioSeparatorDlg::PlayWaveSegment(CString &strFile, int &nSecond)
{
    MCI_OPEN_PARMS mciopenparms;//打开
    MCI_PLAY_PARMS mciplayparms;//播放
    mciopenparms.lpstrElementName=strFile;//播放路径
    mciopenparms.lpstrDeviceType=NULL;//文件类型
    mciSendCommand(0,MCI_OPEN,MCI_DEVTYPE_WAVEFORM_AUDIO,(DWORD)(LPVOID)&mciopenparms);//向MCI设备发送命令消息
    m_count=mciopenparms.wDeviceID;
    mciplayparms.dwCallback=(DWORD)GetSafeHwnd();   
    cdlen=getinfo(MCI_STATUS_LENGTH);    //得到曲目长度                                                                                                                                                                                                                                         
    cdto=MCI_MAKE_HMS(MCI_HMS_HOUR(cdlen),MCI_HMS_MINUTE(cdlen),MCI_HMS_SECOND(cdlen)); 
    cdfrom=MCI_MAKE_HMS(0,0,0);
    //mciplayparms.dwFrom=cdfrom;
    mciplayparms.dwFrom = (nSecond * 1000); // wave data offset, here play
    mciplayparms.dwTo = cdto;
    if(mciplayparms.dwFrom > cdlen || mciplayparms.dwTo > cdlen)
    {
        StopPlay();
    }
    mciSendCommand(m_count,MCI_PLAY,MCI_TO|MCI_FROM,(DWORD)(LPVOID)& mciplayparms);
   
    SetTimer(TIMER_ID, 1000, NULL);
}

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

void CAudioSeparatorDlg::StopPlay()
{
    cdfrom=MCI_MAKE_HMS(0,0,0);
    mciSendCommand(m_count,MCI_CLOSE,0,NULL);
    m_count=0;
    KillTimer(TIMER_ID);
}
 
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐