1. Preface
With the continuous improvement of multimedia hardware environment and software environment, currently, most computer software development involves the application of multimedia software technology.
To design multimedia applications, in principle, multiple levels of tools can be used, ranging from C to multimedia-specific development systems (such as TOOLBOOK, AUTHORWARE, DIRECTOR). However, since multimedia software involves complex and diverse media, has a short development cycle, and requires the participation of a variety of professionals, in order to carry out practical and efficient development, it is necessary to select software that is easy to use and has high development efficiency.
VisualBasic is a Windows programming tool software developed by Microsoft. Because of its advanced design ideas, quick and easy usage, and flexible and diverse means of controlling media objects, it has attracted the attention and favor of multimedia software developers, and has therefore become an ideal tool for multimedia application development.
2. VisualBasic’s multimedia control MCI.OCX
MCI (Media Control Interface) is a media control interface standard provided by Microsoft to achieve device independence under Windows systems. Users can easily use MCI to control standard multimedia devices.
MCI is included in the MMSYSTEM module of the Windows Multimedia Extension, which is used to coordinate communication between events and MCI device drivers, and provides device-independent interface attributes. Usually applications distinguish MCI devices by specifying an MCI device type. The device type specifies the physical type of the device actually currently used. Different device types are described using different control attributes (see Appendix Table 1).
In terms of the control methods used, MCI equipment is divided into two categories: compound and simple. A simple MCI device does not require a device element. For example, CD audio and audio players work on an already installed hard drive and do not require applications to provide any information about the media content they operate on. But for composite MCI devices, the application needs to provide a device element, that is, a source data file or destination file containing all path names.
The CustomControl (user control component) concept of the VisualBasic language reflects the development trend of today's software design - object-oriented technology. Programmers can embed a variety of user controls in the VisualBasic toolbox (Toolbox), and each user controls Components have certain attributes and operation methods. Programmers can complete specific functions by setting attributes and controlling methods. In order to control multimedia conveniently, a user control for multimedia purposes-MCI.OCX is provided in the professional version of VisualBasic toolbox.
Multimedia MCI control MCI.OCX is specially used to record and play back multimedia data files of multimedia control interface MCI devices. In terms of purpose and effect, this control uses a set of buttons to issue various device control commands to achieve control such as: audio panel, MIDI Control of sequencers, CD-ROM drives, audio CD players, video tape playback, audio tape recording and playback, and other equipment. In Visual Basic programming, when adding the multimedia MCI control to the table (double-click the MCI control in the toolbox), the following button groups will appear: forward (PRev), backward (Next), play (Play), pause ( Pause, Back, Step, Stop, Record and Eject.
The application is very flexible and convenient to operate this set of buttons of MCI. For example, when we open an MCI device, we can select the appropriate status button from the control at any time according to the properties of the device type to represent the immediate physical status of the device. All MCI controls can be programmed in the following ways: ⑴ visibility and enablement of the control and its buttons; ⑵ variable or complete redefinition of the control; ⑶ multiple devices can be controlled simultaneously in a window form.
3. Calling of multimedia control component MCI.OCX
In Visual Basic 3.0 Professional Edition, the multimedia control MCI.OCX (in Visual Basic 3.0 and 4.0, the extension of the multimedia control is .VBX) is provided as an optional component. In order to use it, you must first execute the FileAddFile menu command and add MCI.OCX in the Windowssystem directory to the toolbox (Toolbox). At this time, the corresponding MCI.OCX icon will appear in the toolbox. If you are using Visual Basic version 4.0 (or version 5.0), select the oolsCustomControls menu or type Ctrl T directly, a dialog box will appear, select the check box next to the MicrosoftMultimediaControls entry in the AvailableControls list box, and MCI will also appear in the toolbox .OCX icon.
Double-click the multimedia control MCI.OCX icon in the toolbox. After calling the MCI.OCX control, a row of gray media control buttons (nine) will appear in the form FORM.
4. VisualBasic multimedia application design steps
Multimedia control MCI.OCX contains a set of advanced device-independent control commands. When using this multimedia control, first use the OPEN command to open the MCI device (multimedia device) and create a corresponding file to perform operations such as recording or playback (but the corresponding files cannot be used for CDAudio, VCR and video tapes). Once the device is successfully opened, various operating commands (see button commands in the attached table) can be issued to it to complete the specified work tasks. Finally, remember to use the Close command to close devices and data files.
It is very convenient to use MCI.OCX to develop multimedia applications, because most properties are easy to understand, among which the Command property is particularly important, which sends commands to the multimedia device during operation. The format is:
Form.Mmcontrol.Command=cmdstring$
Among them, the cmdstring$ variable is the following executable command name: Open, Close, Play, Pause, Stop, Back, Step, Prev, Next, Seek, Record, Eject, Sound and Save. Once its command is set, it is executed immediately, and any errors that occur are stored in the Error attribute.
The following takes playing DEMO.WAV (waveform file) file as an example to illustrate the design steps of VisualBasic multimedia application.
First, create a form (Form) containing multimedia controls (MCI.OCX), so the control keys shaped like a recorder are displayed on the screen, but at this time the multimedia control components cannot be used immediately (the keys are gray) , the state of the key must be changed through program code.
Secondly, in the Form_Load process, insert the corresponding program code. as follows
SubForm_Load()
'Set the properties of the multimedia device before issuing the OPEN command
Form1.MMControl1.Notify=False
Form1.MMControl1.Wait=True
Form1.MMControl1.Shareable=False
Form1.MMControl1.DeviceType="WaveAudio"
Form1.MMControl1.FileName="c:windowss
Mmdatademo.wav"
Form1.MMControl1.Command="Open"
EndSub
Finally, run the above program and the control keys will be black. At this time, you can use the Play, Record and other keys to operate the data file DEMO.WAV. For example, you can hear the .WAV sound effect by clicking the Play button with the mouse (the computer should be equipped with a pronunciation device).
Through the above statement, it is not difficult to find that VisualBasic uses the multimedia control MCI.OCX to set up a program that is easy to master.
5. VisualBasic multimedia application design examples
1. Play CD music
Many multimedia software systems provide laser disc player software. Using the multimedia control MCI.OCX, we can easily program a simple laser disc player that meets our own requirements.
Table 1 gives the definition of the main control components of a simple CD player, followed by the source program code corresponding to each trigger event.
The complete source program listing is as follows:
`CD player utility
`Please load a laser disc in the CD-ROM drive before running the program' The "LOAD" button triggers the event
PrivateSubCommand1_Click()
`Load the CD record
OnErrorGoToMCI_ERROR
MMControl1.Command="Open"
OnErrorGoTo0
`Set time format
MMControl1.TimeFormat=vbMCIFormatTmsf
`Close the LOAD button and display the picture
Command1.Enabled=False
Picture1.Picture=Picture3.Picture
`Set the initial number of tracks
Label1.Caption="1"
ExitSub
MCI_ERROR:
DisplayErrorMessageBox
ResumeMCI_EXIT
MCI_EXIT:
UnloadCD
EndSub
PrivateSubForm_Load()
MMControl1.Wait=True
MMControl1.UpdateInterval=0
`Set device type
MMControl1.DeviceType="CDAudio"
`Set the default track number to 0
Label1.Caption="0"
ndSub
PrivateSubForm_Unload(CancelAsInteger)
MCITest.Show
EndSub
'"Output" button triggers event
PrivateSubMMControl1_EjectClick(CancelAsInteger)
Command1.Enabled=True
Picture1.Picture=Picture2.Picture
MMControl1.UpdateInterval=0
OnErrorGoToMCI_ERROR2
MMControl1.Command="Eject"
MMControl1.Command="Close"
OnErrorGoTo0
Label1.Caption="0"
Label3.BackColor=&H404040
ExitSub
MCI_ERROR2:
DisplayErrorMessageBox
ResumeNext
EndSub
'The "forward" button triggers the event
PrivateSubMMControl1_NextCompleted(ErrorCodeAsLong)
Label1.Caption=Str$(MMControl1.Track)
EndSub
'The "Pause" button triggers the event
PrivateSubMMControl1_PauseClick(CancelAsInteger)
MMControl1.UpdateInterval=0
Label3.BackColor=&H404040
EndSub
'The "play" button triggers the event
PrivateSubMMControl1_PlayClick(CancelAsInteger)
MMControl1.UpdateInterval=1000
Label1.Caption=Str$(MMControl1.Track)
EndSub
'The "Back" button triggers the event
PrivateSubMMControl1_PrevCompleted(ErrorCodeAsLong)
Label1.Caption=Str$(MMControl1.Track)
EndSub
PrivateSubMMControl1_StatusUpdate()
Label1.Caption=Str$(MMControl1.PositionAnd&HFF)
IfMMControl1.Mode=vbMCIModePlayThen
Label3.BackColor=&H80FF&
Else
Label3.BackColor=&H404040
EndIf
EndSub
'The "Stop" button triggers the event
PrivateSubMMControl1_StopClick(CancelAsInteger)
MMControl1.UpdateInterval=0
Label3.BackColor=&H404040
MMControl1.To=MMControl1.Start
MMControl1.Command="Seek"
MMControl1.Track=1
Label1.Caption="1"
EndSub
2. Play AVI (Audio Video Interface) files
Movies (including sound and images) are one of the media information that most computer workers are most concerned about, and movie processing technology is also one of the key multimedia technologies. In multimedia systems, AVI (Audio Video Interface) files are a standard format for storing movies (including sounds and images). These AVI files are generally obtained by capturing real-time video signals, or images can be obtained through a scanner or Obtained using animation software. Therefore, the audio and video operations on the screen window become the processing of AVI files (the file suffix is AVI). In actual work, there are many ways to play AVI files (i.e. videos), among which the method of using Visual Basic's multimedia control is the simplest and most convenient. The following is a specific example to illustrate how to play an AVI file: Assume that there is a video and audio file named DEMO.AVI in the user's current directory, and using VisulBasic to play the video requires the following steps:
(1) Add an MMControl multimedia control, a PictureBox picture box control and two ComandButton command button components to the Visual Basic form;
(2) Set the properties of each control, where the form is named Form1, the MMControl multimedia control is named MMControl1, the PictureBox picture box control is named Picture1, and the two ComandButton command button controls are named Play and Close respectively;
(3) Write each trigger event source program code and run it. The source code is:
PrivateSubPlay_Click()
MMControl1.Filename="DEMO.AVI"
MMControl1.DeviceType=="AVIVIDEO"
MMControl1.hWndDisplay=Picture1.hWnd
MMControl1.Command="OPEN"
MMControl1.To=1
MMControl1.Command="SEEK"
MMControl1.Command="PLAY"
EndSub
PrivateSubClose_Click()
MMControl1.Command="STOP"
MMControl1.Command="CLOSE"
EndSub
It is worth noting that before playing AVI files, the AVI (audio video) driver should first be installed under Windows. The AVI driver name is MCIAVI.DRV. It must be copied to the WINDOWS SYSTEM directory and added to the [MCI] section of the SYSTEM.INI file:
AVIVIDEO=MCIAVI.DRV
In this way, when running Windows, Windows will automatically install the AVI driver.
The above only describes the operation process of using the multimedia control component to play audio files (.WAV), CD records and audio and video files (.AVI). In fact, the multimedia control component can also be used to play animation files (.FLI, .FLC), MIDI files and other media information.
6. Conclusion
From the previous discussion, it is not difficult to see that using the multimedia control component MCI.OCX provided by Visual Basic, the majority of computer users can develop various multimedia applications conveniently, quickly and efficiently. But it needs to be emphasized that when developing and designing Visual Basic multimedia applications, in addition to using multimedia control components, other means can also be used, such as calling API functions, etc. (In view of the length, this is not discussed here). It can be seen that Visual Basic is indeed an ideal development tool for both professional and non-professional multimedia software developers.
Appendix 1 MCI device type definition
Device TypeDevice Description
CDAudio laser disc player
DAT digital tape audio player
DigitalVideo dynamic digital video imaging equipment
Animation animation playback equipment
Other MCI devices for which no standard definition is given
Overlay simulates video image overlay device
Sequence MIDI sequencer
VCR program-controlled disk recorder
VideoDisc can use program-controlled laser video disc players
WaveAudio is a device that plays digital waveform audio???
Appendix 2 List of unique events for multimedia control components
Event description
Done completes the MCI command action (Notify is true)
ButtonClick click button
ButtonCompleted button execution command completion
ButtonGetFocus button gets input focus
ButtonLostFocusButton lost input focus
StatusUpdate updates the status information of the media control object->