Visual Basic 6 Black Book:Multimedia
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 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
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
Playing CDs From Your CD-ROM Drive
The Testing Department is calling again. Wheres that program to play CDs from the users CD-ROM drive? On its way, you say.
Its easy to create a program that will play music CDs in your computers CD-ROM drive. Just add a multimedia control, MMControl1, to a form, and a label, Label1, which well use to display the players current operation (for example, playing, stopped, and so on).
When the form loads, we just set the multimedia controls DeviceType property to CDAudio and open the device:
Private Sub Form_Load()
MMControl1.DeviceType = "CDAudio"
MMControl1.Command = "Open"
End Sub
Thats all it takes. Now the user can play the CD in the computers CD-ROM drive by using the buttons in the multimedia control.
Besides playing the CD, we can display what the multimedia control is doing in a label, Label1, by adding this code to the multimedia controls StatusUpdate event handler:
Private Sub MMControl1_StatusUpdate()
Dim strMode As String
strMode = ""
Select Case MMControl1.Mode
Case mciModeReady
strMode = "Ready."
Case mciModeStop
strMode = "Stopped."
Case mciModeSeek
strMode = "Seeking."
Case mciModePlay
strMode = "Playing."
Case mciModeRecord
strMode = "Recording."
Case mciModePause
strMode = "Paused."
End Select
Label1.Caption = strMode
End Sub
Finally, we stop the CD (if it hasnt already been stopped) and close the multimedia control when the form is unloaded:
Private Sub Form_Unload(Cancel As Integer)
MMControl1.Command = "Stop"
MMControl1.Command = "Close"
End Sub
TIP: You can even eject a CD with the multimedia controls Eject command, if the CD drive supports that command.
The program is ready to runrun it now as shown in Figure 22.3 (weve added a few more labels to hold captions like CD Player and so on in the program there). If you have loaded a music CD into your CD-ROM drive, you should be able to play that CD using the CD player program.
Figure 22.3 Our Visual Basic CD player.
The code for this program is located in the cdplayer folder on this books accompanying CD-ROM.
TIP: If you dont have a sound card in your computer (and so no speakers) but still want to play CDs with our CD player program, dont despair just yetmost modern CD-ROM drives come with an earphone jack in the front. Just plug your earphones right in.
Playing WAV Files
The Testing Department is calling again. Hows that program that plays WAV sound files coming? Coming right up, you say.
Its easy to write a program to play WAV files using the multimedia controljust set the controls FileName property to the name of the file to open, and open it with the Open command. The multimedia controls buttons will become active at that point, and users can play the file as they like, or, if youve hidden the multimedia control, you can use its Command property to play the file with the Play command.
TIP: If you really just want to play sounds under program control, you can avoid the heavy drain on system resources by interfacing directly to Windows to play sounds instead of using a multimedia control. See Multimedia Without Multimedia Controls near the end of this chapter.
Lets see an example. Here, we set the file to work with to C:\windows\media\ding.wav (which comes with Windows) and then open that file, making the buttons of the multimedia control, MMControl1, active when the form loads:
Private Sub Form_Load()
MMControl1.FileName = "C:\WINDOWS\MEDIA\DING.WAV"
MMControl1.Command = "Open"
End Sub
Now the user can play the WAV file using the multimedia controls buttons.
Besides playing the WAV file, we can display what the multimedia control is doing in a label, Label1, by adding this code to the multimedia controls StatusUpdate event handler:
Private Sub MMControl1_StatusUpdate()
Dim strMode As String
strMode = ""
Select Case MMControl1.Mode
Case mciModeReady
strMode = "Ready."
Case mciModeStop
strMode = "Stopped."
Case mciModeSeek
strMode = "Seeking."
Case mciModePlay
strMode = "Playing."
Case mciModeRecord
strMode = "Recording."
Case mciModePause
strMode = "Paused."
End Select
Label1.Caption = strMode
End Sub
Finally, we stop playback (if it hasnt already been stopped), and close the multimedia control when the form is unloaded:
Private Sub Form_Unload(Cancel As Integer)
MMControl1.Command = "Stop"
MMControl1.Command = "Close"
End Sub
Thats all we need. Now run the program as shown in Figure 22.4 (weve added a label to the program to display a caption). When you click the Play button, the WAV file will be played. Our program is a success.
Figure 22.4 Playing WAV files from Visual Basic.
The code for this example is located in the wavplayer folder on this books accompanying CD-ROM.
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
ReadMe (757)pacjenciid&753ReadMe (753)755 757LX756 757757 759750 753204 208id(75720030817175045id!753mbdch20 757755 757757? slovniky1więcej podobnych podstron