VC + + Simple Operation MP3 Music method, summary

Source: Internet
Author: User

#include <windows.h>#include<stdio.h>#include<mmsystem.h>#include<shellapi.h>#include<afxcom_. H>#pragmaComment (lib, "Winmm.lib")voidMain () {Charstr[ -]={0};inti =0; Charbuf[ -]={0}; Mci_open_parms Mciopen; Mcierror Mcierror; Mciopen.lpstrdevicetype="MPEGVideo"; Mciopen.lpstrelementname="C://1.mp3"; Mcierror= Mcisendcommand (0, Mci_open,mci_open_type | Mci_open_element, (DWORD) &Mciopen); if(mcierror) {mcigeterrorstring (Mcierror,buf, -); printf ("%s/n", BUF); GotoError;} UINT DeviceID=Mciopen.wdeviceid;  Mci_play_parms Mciplay; Mcierror= Mcisendcommand (Deviceid,mci_play,0, (DWORD) &mciplay); if(mcierror) {printf ("send Mci_play command failed/n"); GotoError;}//winexec ("Sndvol32.exe", SW_SHOWNORMAL);//This can turn on the volume control but can be programmed to implement.    while(1) {sprintf (str,"play time:/t%d", i); printf ("%s/r", str); I++; Sleep ( +); }error:system ("Pause"); }
Play MP3 with MCI
Main variable definition

Mci_open_parms Mciopen; Mcierror Mcierror; Mci_status_parms mcistatusparms; WORD M_wdeviceid;

Only the Mcisendcommand command is introduced here.

0. Turn on the device

= Mcisendcommand (0, Mci_open,mci_open_type | Mci_open_element, (DWORD) &

After the device is turned on, the ID of the device is acquired, and all subsequent operations must use this ID number, namely:

UINT DeviceID = Mciopen.wdeviceid;

1. Play

" MPEGVideo "  =fileName.  GetString ();     = Mcisendcommand (M_wdeviceid,mci_play,0 , (DWORD) &mciplay);
The M_wdeviceid here is the device ID that gets when the device is turned on

2. Pause

Mcisendcommand (Mciopen.wdeviceid,mci_pause,null, NULL);

3. Stop

Mcisendcommand (Mciopen.wdeviceid,mci_stop,null, NULL); Mcisendcommand (mciopen.wdeviceid,mci_seek,mci_seek_to_ START, NULL);

4. Get Playback Progress

mcistatusparms.dwitem=mci_status_position;    Mcisendcommand (m_wdeviceid,mci_status,mci_wait| Mci_status_item, (DWORD) (LPVOID) &mcistatusparms); // key, get position    int M_dposition=mcistatusparms.dwreturn;

5. Length of time to get the entire audio

UINT DeviceID = Mciopen.wdeviceid; Mcistatusparms.dwitem=mci_status_length;  Mcisendcommand (deviceid,mci_status,mci_wait| Mci_status_item, (DWORD) (LPVOID) &mcistatusparms); // key, get length     M_dlength=mcistatusparms.dwreturn;

6. Play in the specified position

mci_play_parms mciplay; mciplay.dwfrom=Mcisendcommand (M_wdeviceid,mci_play,mci_from, (DWORD) &mciplay);


7. Control the volume

mci_dgv_setaudio_parms Mcisetaudiopara;   =//Here is the value of theVolume (0--1000)  mcisendcommand (M_wdeviceid, Mci_setaudio, Mci_dgv_setaudio_value | Mci_dgv_setaudio_item, (DWORD) (LPVOID) &mcisetaudiopara);

VC + + Simple Operation MP3 Music method, summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.