win32 播放MP3音频

播放MP3文件
#include 
#pragma comment(lib, "WINMM.LIB")

MCI_OPEN_PARMS m_mciOpen;  //打开参数  
MCI_PLAY_PARMS m_mciPlay;  //播放参数  
bool PlayMP3(char * szFileName)   
{   
    m_mciOpen.lpstrDeviceType = "mpegvideo"; //要操作的文件类型  
    m_mciOpen.lpstrElementName = szFileName; //要操作的文件路径  
    MCIERROR mcierror = mciSendCommand( 0,MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT ,(DWORD)&m_mciOpen); //打开文件命令  
    if(mcierror)
    {  
        return false;  
    }
    else
    {  
        m_mciPlay.dwCallback = (DWORD)NULL;  
        m_mciPlay.dwFrom = (DWORD)0; //播放起始位置ms为单位  
        mciSendCommand(m_mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY|MCI_FROM, (DWORD)(LPVOID)&m_mciPlay);
    }  
    return true;  
}  

void CloseMp3()
{
    mciSendCommand(m_mciOpen.wDeviceID, MCI_CLOSE, NULL, NULL);
}

你可能感兴趣的:(win32 播放MP3音频)