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
Listing 16.2 Code in SOUND1.FRM.
Option Explicit
Private 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
Private Declare Function mciGetErrorString Lib winmm Alias _
mciGetErrorStringA (ByVal dwError As Long, ByVal lpstrBuffer _
As String, ByVal uLength As Long) As Long
Constant for the MCI alias since well only
have one device open at a time.
Const ALIAS = MyDevice
Private Sub Form_Load()
Set up the Open dialogs filter.
CommonDialog1.Filter = _
WAVE (*.WAV)|*.wav|MIDI (*.MID)|*.mid|Video (*.AVI)|*.avi
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim cmd As String, ret As String * 255, x As Long
When the form unloads be sure the device is closed.
cmd = close & ALIAS
x = mciSendString(cmd, ret, 255, 0)
End Sub
Private Sub mnuFileExit_Click()
End
End Sub
Private Sub mnuFileOpen_Click()
Dim cmd As String, devicetype As String, ret As String * 255
Dim rv As Long, rv1 As Long
Display the Open dialog.
CommonDialog1.ShowOpen
Exit if user canceled.
If CommonDialog1.filename = Then Exit Sub
Get the selected file name extension.
cmd = UCase$(Right$(CommonDialog1.filename, 3))
Set the type argument depending on the
extension of the file selected.
Select Case cmd
Case AVI
devicetype = avivideo
Case MID
devicetype = sequencer
Case WAV
devicetype = waveaudio
Case Else
MsgBox (Invalid file format)
Exit Sub
End Select
Set up the MCI command and send it.
cmd = open & Chr$(34) & CommonDialog1.filename & Chr$(34) & _
type & devicetype
cmd = cmd & alias & ALIAS
rv = mciSendString(cmd, ret, 255, 0)
On error.
If rv <> 0 Then
rv1 = mciGetErrorString(rv, ret, 255)
MsgBox (Error opening device: & ret)
Exit Sub
End If
Send the play command.
cmd = play & ALIAS
rv = mciSendString(cmd, ret, 255, 0)
If rv <> 0 Then
rv1 = mciGetErrorString(rv, ret, 255)
MsgBox (Error playing device: & ret)
Exit Sub
End If
Play command successful. Enable the timer and set a 1000 msec interval.
Disable the File menu.
Timer1.Interval = 1000
Timer1.Enabled = True
mnuFile.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim cmd As String, ret As String * 255, rv As Long
Each time the timer counts down, check the MCI device to see if it
is still playing.
Set up the MCI command and send it.
cmd = status & ALIAS & mode
rv = mciSendString(cmd, ret, 255, 0)
If the mode is not playing then we are done and can close the device,
disable the timer, and enable the File menu.
If Left$(ret, 7) <> playing Then
cmd = close & ALIAS
rv = mciSendString(cmd, ret, 255, 0)
Timer1.Enabled = False
mnuFile.Enabled = True
End If
End Sub
Using The Visual Basic Multimedia Control
The second method for sending MCI commands is Visual Basics Multimedia control. When displayed on a form, this control provides an array of buttons for controlling a multimedia device. The control is shown in Figure 16.2. The buttons are defined, from left to right, as Prev(ious), Next, Play, Pause, Back, Step, Stop, Record, and Eject.
The first step in using the Multimedia control is to set its FileName property or its DeviceType property. Set the FileName property when the data to be played is in a file that specifies the type of device to be openedfor example, WAV, MIDI, and AVIVideo files. Set the DeviceType property when the device does not use filessuch as CD Audio or with a compound device where the associated files extension does not specify the type of device.
Next, open the device by setting the Multimedia controls Command property to Open. The control takes care of the details of sending the command to the MCI and obtaining the necessary information about the device. When it comes to actually manipulating the device, you have two choices:
Have the control visible on screen (Visible property = True). When the user clicks on the buttons on the control, the appropriate commands are sent to the device.
Hide the control (Visible property = False). To execute commands, place them in the controls Command property.
Of course, you can use these two methods in tandem. If the control is visible, you can still send commands by placing them in the Command property. Likewise, if the control is hidden, it can be made visible if needed.
Much of the appeal of the Multimedia control lies in simplifying tasks that would be more difficult to accomplish by directly accessing the MCI, as shown earlier in this chapter. The control has many properties that correspond to information about the open multimedia device, such as the information accessible with the Capabilities command. For example, simply read the Multimedia controls CanEject property to determine if the open device can eject its media, and read the Mode property to determine the current state of the device. Lets take a closer look at some of these properties (refer to Visual Basic Help for details on all Multimedia control properties).
Figure 16.2 The Multimedia control.
Multimedia Control Properties
The Mode property returns one of the following values (as a type Long ), indicating the current mode of the open device as shown in Table 16.4.
The CanEject, CanPlay, CanStep, and CanRecord properties return True or False, depending on whether the open device has the indicated capability.
The AutoEnable property determines if the individual buttons on the Multimedia control are automatically enabled and disabled to reflect the capabilities of the open device (AutoEnable = True), or whether the program must enable and disable individual buttons by setting the corresponding ButtonEnabled property (AutoEnable = False), where Button is either Back, Eject, Next, Pause, Play, Prev, Record, Step, or Stop.
The Enabled property controls user access to the entire Multimedia control. If Enabled is set to False, the user cannot select any of the controls buttons.
Wyszukiwarka
Podobne podstrony:
Badanie płytą 16 05 13 MC 20 ( rondo 1 w wa)16 05 2012 19 47 02 20wątroba materiały 16 05 201216 05Geodezja wykład 8 9 pomiary wysokościowe (9(16) 05 2011)Wykład 16 05 2009r 05 05 16 pra05 16więcej podobnych podstron