MCI, a high-level interface for controlling multimedia devices under Windows, defines functions and data types that call MCI functionality in <mmsystem.h>, which provides a set of device-independent APIs for controlling multimedia devices.
The application controls the MCI device by sending a command message to the MCI device.
The following code implements the ability to play MP3 playback with MCI:
#include <Windows.h>
The header file to include and the linked library.
#include <mmsystem.h> #pragma Comment(lib,"Winmm.lib") BOOL playfile(TCHAR* szfilepath) { mci_open_parms mciopen; mcierror mcierror; mciopen. Lpstrdevicetype = "MPEGVideo" ; mciopen. Lpstrelementname = Szfilepath ; //OpenMCIEquipment mcierror = mcisendcommand(0,mci_open, mci_open_type | mci_open_element , (DWORD) & Mciopen ); if (mcierror!=0) return FALSE; UINT DeviceID = mciopen. Wdeviceid ; mci_generic_parms mcigeneric; mcierror=mcisendcommand(DeviceID,Mci_window , 0, (DWORD) &mcigeneric); if (mcierror!=0) return FALSE; mci_play_parms mciplay; //Play mcierror = mcisendcommand(DeviceID,mci_play , 0 , (DWORD) & Mciplay ); if (mcierror!=0) return FALSE; return TRUE; }int _tmain(int argc, _tchar* argv[]) { BOOL bisplaying=playfile("e:\\ Music-Songs\\ji jing\\the freedom of Loneliness. mp3 ");While (bisplaying) { Sleep(+); } return 0; }
Introduction to the MCI programming of Windows multimedia programming