frankkanks@yahoo.com.cn
The following is the reference of the program (detailed)
Overview of MCI command strings
MCI command string is the program interface of multimedia equipment. Through it, we can open a multimedia file, such as mp3 file, VCD file, Mpeg4-4 file, and play, pause and close it. Now I am honored to introduce you to the use of MCI command strings.
The MCI command string is executed by two functions: mciExecute or mciSendString. These two functions are declared as follows:
The private declaration function mciExecute Lib "winmm.dll "alias" mciexecute "(byval lpstr command as string) is Long.
Private declaration function mcisendStringlib "winmm.dll" alias "mcisendStringa" (byval lpstr command is string, ByVal lpstrReturnString is string, ByVal uReturnLength is Long, ByVal hwndCallback is Long) is Long.
Both functions have a parameter named lpstrCommand, which is the MCI command string we will introduce today. The function mciSendString also has three parameters, and lpstrReturnString is a string used to receive the information returned by mciSendString function (for example, our command in lpstrCommand is to let the function return the device type of the open file, so the function saves the information of the device type in this parameter. ); UReturnLength parameter is used to specify the length of lpstrReturnString parameter; HwndCallback is the window handle that receives "Wait" and "Notify" messages. This parameter can be set to 0 when called in Visual Basic. If the command is executed incorrectly, the function mciExecute will pop up a dialog box directly, prompting the reason for the error. The mciSendString function will return an ErrorCode, which can refer to the directory "platform SDK \ graphics and multimedia services \ windows multimedia \ multimedia reference \ multimedia constants \ mcierr return values" of MSDN. You can choose which function to use to execute MCI command according to the specific situation. For example, when debugging, use mciExecute to get the cause of the error quickly, and use mciSendString function in the program to be released to let the error trap set in the program handle the error, so as to avoid frequent error prompts from boring users.
After getting familiar with these two functions, we can start to study the business-MCI command string.
The command format of MCI command string is as follows: lpsz command lpsz device lpsz command flag lpazflag.
LpszCommand is mci command, such as open, play, stop, close and so on.
LpszDevice is the device name (or file name). For example, we use the following program to open the Music0 1.dat file in my document and set its alias to OpenFile with the "alias" parameter:
Dim lReturn As long ( 1)
lReturn = MCI execute(" open C:\ my docu ~ 1 \ music 0 1 . dat alias OpenFile type mpeg video ")(2)
Then, in future MCI command strings, the lpszDevice parameter must be specified as OpenFile. For example, the code to close a file is as follows:
lReturn = MCI execute(" close OpenFile ")(3)
If we don't set an alias for the opened file, the lpszDevice parameter in the MCI command string to be called later will be the DOS path name plus the file name. Examples are as follows:
Dim lReturn As long(4)
lReturn = MCI execute(" open C:\ my docu ~ 1 \ music 0 1 . dat type mpeg video ")(5)
lReturn = MCI execute(" close C:\ my docu ~ 1 \ music 0 1 . dat type mpeg video ")(6)
Thus, the advantage of setting an alias is to reduce the input of code.
LpszCommandFlag is a parameter of mci command. Like the above code (2), "alias OpenFile" and "type MPEGVideo" are parameters of the command "open". Usually, an mci command has several or dozens of parameters. LpazFlag can be specified as "wait" or "notity". If it is "wait", mci _ wait message will be sent to the parent form after executing MCI command, and "notice" will send MCI _ notity message. This parameter is of little use in Visual Basic.
Let's make it clear that Microsoft supports ten kinds of multimedia devices: cdaudio, dat, digitalvideo, other, overlay, scanner, sequencer, vcr, videodisc and waveaudio (Note: Microsoft does not support files in RealPlay format. You can use the following code to get the type of open file: lreturn = mcisendstring ("capability lpsz device device type", sreturn, 32,0)). As for which type of device supports which parameters, you can look up the keyword "MCI Command Strings" in MSDN and select the listed commands. In an HTML help document, there is usually a table that tells you which devices support which parameters or the information in the first paragraph tells you which devices support this command.
Ok, now let's make a systematic introduction to the complex, damn and powerful mci command parameters. (This article only introduces the common parameters of the open command, and I will introduce the parameters of other commands to you when I have the opportunity. )
Open:
This command is used to open multimedia files. All devices support this command. Before executing any mci command, you must open the multimedia file to initialize the device.
The meanings of several parameters of this command are as follows: alias device _ alias- specifies the alias of the file to be opened; Shareable- whether to open in * * * mode, if this parameter is not specified, it will be opened in * * * mode, that is, after opening a multimedia file, other programs can no longer be opened; if this parameter is specified, it will be opened in * * * mode; Type device _ type- specifies the multimedia file name of the file registered in Windows (Note: the multimedia file name registered in Windows is different from the device type name, and the device type is only the ten types mentioned above. For the multimedia file name registered in Windows, please refer to the [mci Extension] section of the C:\Windows\win.ini file. ), such as MPEGVideo, AVIVideo, waveaudio, etc. The files of MPEGVideo and AVIVideo actually belong to the device digitalvideo.
For the open command, there are several aspects to pay attention to. First of all, when opening a file with the open command, the path of the file must be a short path in DOS format. You can use the API function GetShortPathName to return the format of the path. For the parameter type device_type, files of MCI devices of composite devices (such as MPEG Video) will be automatically registered in Windows according to their extensions (for the type names of files with extensions, please refer to the [mci extensions] section of the file C:\Windows\win.ini). ) (so you don't need to specify this parameter for the extensions listed in the [mci extensions] section of the C:\Windows\win.ini file), but you must specify this parameter if the device cannot obtain the file type according to its extension. If it is not specified, it will prompt: "This is not a registered mci device", but a simple device (such as CD audio track device, programmable video recorder).
If the command is executed successfully, the return value is 0. At this point, you can use the alias specified by alias to execute various mci commands.
Break: Use the wait parameter to specify the key to exit the current mci command.
Ability: Get the functions of the opened device, such as whether it can be played, whether it can be exited, whether it can be recorded, etc.
Capture: Copy the data buffered by the frame to the specified file.
Turn off: Turn off the device and free up memory.
Configuration: Displays a dialog box to set some properties of the device.
Copy: Copy data to the clipboard.
Tip: Executing this command before playing or recording can speed up playing or recording.
Cut: Cut the data in the workspace to the clipboard.
Delete: Delete a data segment from an open multimedia file.
Freeze: Terminates the video input or output and prohibits the video stream from obtaining data from the frame buffer.
Info: get device information, such as algorithm, copyright, open file, UPC, etc.
List: Returns the number and type of video and audio.
Load: Open the file in the format specified by the device. A function similar to open.
Monitor: specifies the current source. The default current source is the current workspace.
Paste: Copies the contents of the clipboard to the workspace.
Pause: Pause playing or recording.
Play: Hehe, there is no need to say more about this command.
Put: determine the display source and display target window area.
Quality: customize the quality level of audio or video and the compression method of still images (such as BMP and JPG).
Implementation: Customize the color palette of the image display window.
Record: Needless to say.
Reserved: Allocate continuous disk space for the device's workspace.
Restore: Copy the static image from the file to the frame buffer.
Resume: Continue playing or recording.
Save: Save an mci file.
Seek: Navigate to the specified frame position and wait.
Settings: Set some parameters. (such as left channel, CD-ROM switch, time format, etc. )
Setaudio: set the audio parameters. (e.g. bass, treble, left channel and right channel)
Setvideo: Set the parameters of video playback or capture. (such as brightness, contrast, gamma value, etc.). ).)
Status: Returns the status information of the open device.
Step: Set the number of frames to step when playing slowly. Negative inversion, in frames per second.
Stop: Needless to say.
Undo: Undo the last copy, cut, delete and paste command.
Thawing: the reverse operation of freezing.
Update: read the data of the current frame and display it in the target window or target DC (device scene).
Where: get the source or target display area specified by the Put command.
Window: Set the window to play. You can use it to set the playback window to another window and cancel the default window.
Channels channel_count: Set the channel to be played or recorded.
Clock Time: Set the external time to the variable "Time". This variable is an unsigned long integer.
Counter Format: Set the counter format.
Counter value: Set the VCR counter to the specified value.
Door closed: Retract the CD tray.
Dooreopen: exit the CD.
File Format Format: Specifies the time format used by the Save or Collect command. If omitted, the default format of the device will be used. If a file format that conflicts with the current algorithm and Quality is specified, the default file format will be used. The following are all defined file formats:
Avi:AVI format; Avss:AVSS format; Dib:DIB format; Jfif:JFIF format; Jpeg:JPEG format; Mpeg:MPEG format; Rdib: RLEDIB format; Rjpeg:RJPEG format
Format label pcm: Set the format of playing or recording to PCM, and the file will be saved in this format.
Format tag: Set the format of playing or recording, and the file will be saved in this format.
Index time code
Index counter
Index date
Index Time: Sets the current display of the VCR.
Input Integer: Set the channel of audio input.
Length Duration: Set the user-specified VCR tape length.
Master midi: Set MIDI sequencer as synchronization source and send synchronization data in MIDI format.
Master None: The MIDI sequencer is prohibited from sending synchronization data.
Master smpte: MIDI sequencer is set as synchronization source, and synchronization data is sent in smpte format.
Offset time: set the SMPTE offset. The format of variable "time" is: hh: mm: ss: ff; Hh is the hour, mm is the minute, ss is the second, ff is the frame.
Output Integer: Sets the channel of audio output.
Pause Timeout: Sets the maximum duration of the Pause command, in milliseconds. 0 means there is no pause.
Postroll duration Duration: Sets the length of time to interrupt the transmission of the VCR when executing the Stop or Pause command in the current time format.
Port mapper: Set MIDI printing as the port to receive MIDI information.
No port: cancel MIDI information transmission.
Port port_number: Set the MIDI port to receive MIDI messages.
electrify
Turn off the power: turn on and off the power of the equipment.
Pre-roll Duration Duration is used to stabilize the length of the VCR output in the current time format.
Recording format SP
Recording format LP
Recording format EP: Set the recording mode of VCR, SP: Play normally; EP: external release; LP long-term playback
Samplespersec integer: Sets the sampling speed of playback or recording, and the file will be saved in this format.
Look for accurately
Precise positioning: Set two positioning modes. "Exact lookup" means assigning bits to a specified frame. "Close search completely" refers to the key frame closest to the specified frame.
Dependent file: Set MIDI sequencer to use file data as synchronization source, which is the default setting.
Slave midi: Sets the MIDI sequencer to use the input MIDI data as the synchronization source. The sequencer recognizes data in MIDI format.
No attribution: Set MIDI sequencer to ignore synchronization source data.
Slave smpte: Sets the MIDI sequencer to use the input MIDI data as the synchronization source. Sequencer recognizes data in SMPTE format.
Speed factor: Set the speed of audio and video playback in the workspace. "Factor" is a proportional value: 1000 means playing at normal speed, 500 means playing at half the normal speed, and 2000 means playing at twice the normal speed. When it is 0, it means playing as fast as possible without losing audio and video frames.
Still file format Format The file format used by the Capture command.
Speed tempo_value: Sets the sequence speed in the current time format.
Time format btyes: In the PCM format file, set the time format to bytes. All location information will be represented as byte values.
Time Format Frame: Sets the time format as a frame.
Time format hms: Set the time format to hours, minutes and seconds.
Time Format Milliseconds: Sets the time format to milliseconds.
Time format msf: Set the time format to minutes, seconds and frames. It is expressed as: mm: ss: ff. Mm is minutes, ss is seconds and ff is frames.
Time format sampling: Set the time format to the sampling frequency.
Time format smpte24
Time format smpte25
Time format SMPTE30: Set the time format to the SMPTE frame speed.
Time format smpte 30 drop: Set the time format to smpte30drop (? )
Time format song pointer: Set the time format as the song pointer.
Time format tmsf: Set the time format to track, minute, second and frame. It is expressed as TT: mm: ss: ff. Tt is the track, mm is the minute, ss is the second, ff is the frame.
Time format tracking: Set the location format to tracking.
Time mode counter: Set the location information mode to use the VCR counter.
Time pattern detection: set the position information pattern to the format of time code information based on the detection band.
Time mode Time code: Set the position information mode of the tape to the format using time code information.
Video off
Video on: Turn off and turn on the video.
Setaudio: Set audio parameters (such as bass, treble, left and right channels). Digital video and video recorders support this command.
Algorithm Algorithm: Select the specified audio compression algorithm. This algorithm will be used for the Hold and Record commands. MCI defines the algorithm as G7 1 1, G72 1, G722, G728, PCM, CDXA, ADPCM and ADPCM 4E.
Align with Integer: Sets the data block queue related to the beginning of input data of the waveform audio device.
Bass Factor: Sets the audio bass value.
Bitspersample to bit _ count: set the number of bits sampled at a time when recording.
Bytespersec to integer: Sets the average number of bytes recorded per second.
Clocktime: specifies that the unit of time used in the "over" parameter is milliseconds.
Input: Activate the settings of parameters "Bass", "Treble" and "Volume". Thereby affecting the playing and recording of signals. This is the default setting.
unused
Left on: Close and open the left channel.
Left channel volume coefficient: Sets the volume of the left channel.
Monitor to Type Number Number: Controls which input source will be delivered to the output of the VCR without changing the selection of recording source. Type can be Output or other valid input source. If "$ number" is not specified, the first input of this type will be selected
leave
On: Turn off and on audio.
Output: Activate the settings of parameters "Bass", "Treble" and "Volume". Make it affect the playing signal, but not the recording signal.
Over duration: specifies how long it will take if the parameter using the "factor" variable changes. Duration is the current time format. If this parameter is not specified, the parameter change will be performed immediately.
Quality descriptor: specifies the compression characteristics of audio when it is recorded to a file. All devices support Low, Medium and High.
Recording off: clear the sound source selection, and the next "recording" command will not record audio data.
Recording on: Open the audio data recording selection. This is the default project.
Track track_number off: clears the audio source selection specified by "track _ number", and the subsequent "Record" command will not record audio data.
Open recording track_number: Opens the audio source selection specified by "track_number".
immediately
Right turn on: Turn off and turn on the audio right channel output.
Right Volume Factor: Sets the volume of the right channel.
Samplespersec to integer: the sampling frequency recorded under the "pcm" or "adpcm" algorithm, and the file is saved in this format.
Source to sourcename: set the audio input source. Sourcename can be left, right, average and stereo, which means left, right, average and stereo respectively.
Source to type number number: Select the audio source to record on tape. The type must be tuner, line, video, auxiliary, general and mute.
Stream to number: specifies the audio stream played back by the workspace. If this parameter is not specified and the default value is not defined in the file, the audio stream first encountered by the audio driver will be played.
Track track_number off: closes the specified track.
Track track_number on: opens the specified track.
Treble coefficient: Set the treble value.
Volume factor: Set the volume of the left and right channels.
According to my experience, the bass value, treble value and volume are between 0 and 1000. There is another important aspect of audio that is easily confused: some friends expect to turn off the left (right) channel to prohibit the sound of the left (right) channel, but the result is that there are still some remaining channels that are not turned off. This is because the default sound source is always stereo, which is to mix the slight right (left) channel sound into the left (right) channel to achieve stereo effect. To completely suppress the sound of a channel, use the "source to sourcename" parameter.
Setvideo: set the parameters of video playback or capture (such as brightness, contrast, gamma value, etc.). ).)。 Digital video devices support this command.
Algorithm Algorithm: Specifies the video compression algorithm to be used for the next "Keep" or "Record" command. MCI has defined "MPEG" and "H26 1". If the specified algorithm conflicts with the current file format, the default algorithm of the file will be used.
Bitsperpel to count: Sets the number of bits per pixel when saving data with Capture or Record.
Brightness coefficient: Set the video brightness.
Clocktime: specifies that the unit of time used for the "over" parameter is milliseconds.
Color factor: Set the video saturation (color).
Contrast factor: Set the video contrast.
Gamma to value: sets the gamma correction value. "Value" 2200 means that the gray scale value is 2.2, and 1000 means that gray scale correction is not performed.
Halftone: Use the halftone palette instead of the default palette.
Input: Activate the parameter settings of brightness, color, contrast, gamma, sharpness and tone, which will affect the input signal and recording signal.
Key Color is r:g:b: Set Key Color to RGB value.
Key Index to Index: Set the Key Index. Index must be the index of the physical palette.
Monitor to Type Number Number: Controls which input source will be delivered to the output of the VCR without changing the selection of recording source. "type"
Number of Tags: Returns the maximum number of masks, with 0 indicating that masks are not supported.
Output: Returns the total number of output devices.
Seek accuracy: returns the accuracy of the positioning frame, where 0 means accurate positioning, and 1 means that the error with the frame to be positioned is not more than 1 frame.
Slow playback speed: Returns the slow playback speed in frames per second.
Uses files: Returns true if the data used by the composite device is saved in a file.
Use Palette: Returns true if the device uses a palette.
Windows: Returns the number of windows supported by the device that can be displayed at the same time.
Capture: Copy the data buffered by the frame to the specified file. Digital video supports this command.
Path Name: Specifies the path and file name to save the captured image in the frame buffer.
Atrrectangle: specifies the image area in the captured frame buffer, and defaults to the area specified by the source parameter of the put command.
Note: This command may fail during playback or operations that require resources. If the frame buffer is updated in real time, it will pause.
Turn off: Turn off the device and free up memory. When all instances or files of MCI devices are closed, MCI devices are uninstalled. All devices support this command.
Note: If you want to turn off all devices, you need to do this: turn off all.
Configuration: Displays a dialog box to set some properties of the device. Digital video supports this command.
Copy: Copy data to the clipboard. Digital video supports this command.
Atrrectangle: specifies the area of the frame buffer to be copied; The default is the entire frame buffer.
Audio Stream: Specifies the audio stream of the current workgroup affected by this command. If this parameter is used and you want to copy a video stream, you must specify the Video Stream parameter. The default value is audio stream+video stream.
From Location: specifies the starting recording point, and defaults to the current location.
To Location: specifies the end point where video and audio streams will not be recorded, and defaults to the end point of the current workgroup.
Video Stream: Specifies the video stream in the workgroup affected by this command. If this parameter is used and you want to copy an audio stream, you must specify the Audio Stream parameter.
Tip: Executing this command before playing or recording can speed up playing or recording. Digital video, VCR and waveform audio support this command.
From Location: Specify the starting point.
Input: Prepare the record. Digital video can be omitted.
Noshow: get ready to play, but don't show off first.
Output: Ready to play. If neither input nor output is specified, the default value is output.
Pre-scroll: Pre-scroll to the next position.
Reverse: Specifies the reverse direction.
Positioning: Specify the end point.
Note: If the device is playing, recording or pausing, this command will fail. When the output parameter is used, the from, to or reverse parameters of the play command will exit the command, and when the input parameter is used, the from, to or initialize parameters of the record command will exit the command.
Cut: Cut the data in the workspace to the clipboard. Digital video supports this command.
Atrrectangle: specifies the area of each frame. The default is the entire frame. When this parameter is specified, the frame will not be deleted, and the original image information will be replaced by black blocks.
Audio Stream: Specifies the specified audio stream of the current workgroup affected by this command. If this parameter is used and you want to cut the video stream, you must specify the "Video Stream" parameter, which defaults to audio stream+video stream.
From position: specifies the starting cutting point, and defaults to the current position.
To Location: specifies the uncut end point, which defaults to the end point of the workgroup.
Video Stream: Specifies the specified video stream of the current workgroup affected by this command. If this parameter is used and you want to cut the audio stream, you must specify the "Video Stream" parameter, which defaults to audio stream+video stream.
Note: Before calling the Save command, although it seems that the Cut command has been successfully played, the deletion made by this command will not be written to the file until calling the Save command.
Delete: Delete a data segment from an open multimedia file. Digital video and waveform audio support this command.
Atrrectangle: Specifies the area to be deleted in each frame. The default is the entire frame. When this parameter is specified, the frame will not be deleted, and the original image information will be replaced by black blocks.
Audio Stream: Specifies the audio stream of the current workgroup affected by this command. If this parameter is used and you want to delete the video stream, you must specify the "Video Stream" parameter. The default value is audio stream+video stream.
Starting position: specify the starting position, which defaults to the current position.
To Location: Specify the end point, which is the end point of the workgroup by default.
Video Stream: Specifies the video stream of the current workgroup affected by this command. If this parameter is used and you want to delete the audio stream, you must specify the "Video Stream" parameter, which defaults to audio stream+video stream.
Note: Before executing any command using the position parameter, you can use the "time format" parameter of the "set" command to set the time format of the media, such as milliseconds, frames, etc.
Escape: Transfer the information specified by the device to a device. The video disc device supports this command.
Freeze: Terminates the video input or output and prohibits the video stream from obtaining data from the frame buffer. Digital video, video overlay and VCR support this command.
Atrrectangle: specify the area. For digital video equipment, the pixels in the designated area will be masked and covered. The format of the rectangle is x 1y 1x2x2. X 1 Y 1 is the coordinate of the upper left corner, and X2 Y2 specifies the width and length.
Field: Freeze the specified area. This parameter is the default value.
Frame: Freeze the whole frame.
Input: Freeze the current frame of the input image, whether it is currently playing or paused.
Output: Freeze the current frame output of the VCR. If the VCR executes this command while playing, the current frame will be frozen and the VCR will pause. If VCE is paused, the current frame will be frozen. If neither input nor output is specified, the default value is output.
External: Specifies the frozen part outside the area defined by the "at" parameter.
Note: To specify an irregular area, you can use the freeze and unfreeze commands in combination. Some video overlay devices will limit the complexity of this area.
Index: Controls the actual screen display of the VCR device. Only VCR devices support it.
Off: Turn off the real screen display.
On: Turn on the real screen display. The displayed item is the information specified by the "index" parameter of the "set" command.
Info: get device information, such as algorithm, copyright, open file, UPC, etc. All MCI devices support this command.
Audio algorithm: returns the name of the current audio compression algorithm.
Audio quality; Returns the description of the current audio compression quality. If you set its quality to a certain value without using its specified value, you may return unknown.
Copyright: Returns the copyright information of MIDI files.
File: Returns the file name used by the composite device. If the device does not open a file and the "load" command is not used, an empty string is returned.
Information identification: generate a unique serial number for the CD.
Information upc: UPC (Universal Product Code Global Product Code) used to generate CDs.
Input: Returns the description of the current input device.
Name: Returns the name of the sequence.
Output: Returns the description of the current output device.
Product: Returns the description of the device. The information returned usually includes the product name and model number. The information returned is usually 3 1 byte or less.
Static Algorithm: Returns the name of the current still image compression algorithm.
Still quality: returns the description name of the compression quality of the current still image. If you set its quality to a certain value without using its specified value, you may return unknown.
Usage: Returns the usage restriction description of video and audio data in the workgroup.
Version: Returns the version of the device driver or hardware.
Video Algorithm: Returns the name of the current video compression algorithm.
Video Quality: Returns the description name of the current video compression quality. If you set its quality to a certain value without using its specified value, you may return unknown.
Window Text: Returns the title of the window used by the device.
List: Returns the number and type of video and audio. Digital video and video recorders support this command.
Audio Algorithm: Returns the name of the audio compression algorithm.
Audio Quality Algorithm: Returns the compression quality level specified by Algorithm. If the "algorithm"