(Note: This article is based on the MSDN explanation in July 2000)
MCI Command String is a program interface for multimedia devices. Through it, we can open a multimedia file, such as mp3, VCD file, Mpeg4 format file, etc., and perform operations such as playing, pausing, closing, etc. on it. Now I have the honor to introduce to you how to use MCI Command String. MCI Command String is executed through the two functions mciExecute or mciSendString.
The declarations of these two functions are as follows:
Private Declare Function mciExecute Lib winmm.dll Alias mciExecute (ByVal lpstrCommand As String) As Long Both Long functions have a parameter called lpstrCommand. This parameter is the MCI Command String we are going to introduce today.
The function mciSendString also has three parameters. lpstrReturnString is a string, which is used to receive the information returned by the mciSendString function (for example, our command in lpstrCommand is to let the function return the device type of the open file, then the function returns the device type The information is stored in this parameter. ); the uReturnLength parameter is used to specify the length of the parameter lpstrReturnString; hwndCallback is the window handle that receives wait and notify messages. In Visual This parameter can be set to 0 when called in Basic. If an error occurs during the execution of the ming command, the function mciExecute will directly pop up a dialog box to prompt the cause of the error. The mciSendString function will return an ErrorCode (error code). For the specific meaning of this code, you can refer to the directory Platform SDKGraphics and Multimedia ServicesWindows MultimediaMultimedia ReferenceMultimedia ConstantsMCIERR Return Values in MSDN. You can choose which function to use to execute the MCIming command according to the specific situation. For example, use mciExecute when debugging to quickly obtain the cause of the error, and use the mciSendString function in the program to be released to let the error trap set in the program handle the error to avoid frequent error prompts that annoy users. . After becoming familiar with these two functions, we can get to the point?D?DMCI Command String.
The command format of MCI Command String is as follows: lpszCommandlpszDevicelpszCommandFlaglpazFlaglpszCommand is the mciming command, such as open, play, stop, close, etc. lpszDevice is the device name (or file name). For example, we use the following program to open the Music01.dat file in My Documents, and use the alias parameter to set its alias to OpenFile: dim lReturn as long
(1)lReturn=mciExecute(open C:Mydocu~1Music01.dat alias OpenFile type MPEGVideo)
(2) Then, the lpszDevice parameter must be specified as OpenFile in future MCI Command String. For example, the code to close the file is as follows: lReturn=mciExecute(close OpenFile)
(3) If we do not set an alias for the opened file, the lpszDevice parameter in the MCI Command String called later is the DOS path name plus the file name. An example is as follows: dim lReturn as long
(4)lReturn=mciExecute(open C:Mydocu~1Music01.dat type MPEGVideo)
(5)lReturn=mciExecute(close C:Mydocu~1Music01.dat type MPEGVideo)
(6) It can be seen from here that the advantage of setting aliases is to reduce code input.
LpszCommandFlag is a parameter of the mciming command.
As shown in the above code (2), alias OpenFile and type MPEGVideo are the parameters of the open command.
Usually the parameters of an mciming command range from a few to dozens. LpazFlag can be specified as wait or notity. If it is wait, then after the mciming command is executed, the MCI_WAIT message will be sent to the parent form, and notity will send the MCI_NOTIFY message.
This parameter is of little use in Visual Basic. Let me declare here that there are ten types of multimedia devices supported by Microsoft: cdaudio, dat, digitalvideo, other, overlay, scanner, sequencer, vcr, videodisc, and waveaudio (Note: Microsoft does not support RealPlay format files. You can use the following The code gets the type of the opened file: lReturn=mciSendString(capability lpszDevice device type,sReturn,32,0) ). As for which type of device supports which parameters, you can search for the keyword MCI Command Strings in MSDN and select the listed command. There is usually a table in the HTML help document telling you which devices support which parameters or in There is information in the first paragraph telling you which devices support the command.
Okay, now let us make a systematic introduction to the complicated, damning, and powerful mciming command parameters. (This article only introduces the common parameters of the openming command. I will introduce the parameters of other ming commands to you when I have the opportunity.) open: This ming command is used to open a multimedia file. All devices support this ming command. Before any mciming command is executed, the multimedia file must be opened to initialize the device.