16 02 P2E75XT3GTP4R4QQJBFCJMR5DQXNZZV2PJPHSTQ




Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Multimedia Magic
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




MCI Commands
A program controls multimedia devices by means of MCI commands, a remarkably simple set of commands applicable to all multimedia devices. Although some commands are specific for certain devices, the basic sequence of steps for using a multimedia device usually goes like this:


1.  Open the device. For some devices, this step includes specifying the file where the data is stored—for example, a WAV file on disk. For other devices, such as playing audio from a CD or video from a videodisc, the data is part of the device, so there is no file to open.
2.  Play the device (or, in some cases, record). This step may include pausing, seeking to a new location in the data, and so on.
3.  Close the device.

Let’s take a look at some simple MCI commands. To play a WAV file—perhaps CHIMES.WAV, which comes with Windows—here is the first command:



Open c:\media\chimes.wav type waveaudio alias chime


The Open command opens the desired WAV file, specifies its type (from Table 16.1), so Windows knows which driver to use, and assigns an alias— a name you can use in subsequent commands to refer to this device. Opening the device does not actually play the sound. The command for that is:


Play chime


You use the Play command with the alias assigned to the device. The sound will start playing, and control will pass back to the program. Although CHIMES.WAV is a short sound, you can play longer sounds that continue to play to the end while the program performs other tasks. When you finish with the device, you close it as follows:


Close chime


The Close command terminates play, so you have to delay its execution until the sound has completed playing. I’ll show you how to do this later.
The basic MCI commands are listed in Table 16.2, although you will not be exploring them all here. My goal is to show you how to perform the most common multimedia tasks in your Visual Basic program. For more details about multimedia, refer to one of the books published on the topic.
Table 16.2 The basic MCI commands.



Command
Action

Capability
Requests information about a device’s capabilities

Close
Closes a device

Info
Requests specific information about a device (such as its driver name)

Open
Opens and initializes a device

Pause
Suspends playback or recording

Play
Starts playback

Record
Begins recording

Resume
Resumes play or recording on a paused device

Save
Saves recorded data

Seek
Moves to a specific position on the media

Set
Changes a device’s control settings

Status
Obtains device status information

Stop
Stops playback or recording




Note that you cannot simply type these commands into Basic code; you have to send them to the MCI. How? Examining the two available methods is the topic for the remainder of this chapter.

Sending MCI Commands With mciSendString
One way to send commands to the MCI is to use the function mciSendString. Not a part of Visual Basic, this function is part of the Windows Applications Programming Interface (API), the huge collection of functions that provides most of Windows’ capabilities. When a Visual Basic program—or one written in any other language, for that matter—performs any operating system-related task, it is actually calling Windows API functions to do the job. When you open a file by writing code in Basic, Visual Basic translates it into the necessary Windows API call to perform the task. Not all API capabilities are included in Visual Basic; but fortunately, when you run into this situation, you can call the API function directly—which is exactly what you will do here.
Before a program can use a Windows API function, you must declare it. The declaration provides the program with certain information about the function, such as its name, the library it is in, and the number and types of its arguments. You can save time by copying API function declarations from the API Text Viewer application (typically installed along with Visual Basic) and pasting them into our code.

TIP:  Using The API Text Viewer
The API Text Viewer is part of the default Visual Basic installation. To run it, find the entry “API Text Viewer” on your Windows Start menu (its exact location on the menu depends on your Visual Basic installation. Select Open Text File from the File menu, and load WIN32API.TXT. Then in the API Type box select Constants (to view predefined Windows constants), Declares (to view Windows API function declarations), or Types (to view predefined Windows data types). Select an item in the Available Items list and click on Add to put it in the Selected Items list. Once you have all the desired items selected, click on the Copy button to copy the contents of the Selected Items box to the Clipboard. Switch to Visual Basic and paste the items into your code.



Here’s the declaration for the mciSendString function:


Declare Function mciSendString Lib “winmm” Alias “mciSendStringA” _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long


This declaration tells you the following:


•  The function is named mciSendString.
•  It is located in the library named WINMM (a library is a disk file where Windows keeps its functions).
•  Its alias (the name it goes under in the library) is mciSendStringA. While this alias is essential for the function declaration, it has no other relevance to your program.
•  It takes four arguments—two Strings and two Longs.
•  It returns a type Long value.





Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this si

Wyszukiwarka