Contents
Sound API  Sample Help

Sample Description: Sound API

Points of Interest

Declaring a Sound Function

Playing a Sound File

Control

AudioPlayer

For Help on Help, Press F1


Sound API

Windows provides many sound API's that provide several types of functionality. In this particular sample, you are shown how to play a sound file (.wav) directly from your application. This is accomplished by declaring a function that interfaces to a Windows API, then calling that function from your application program.

To run the sample:

1.	Click on one of the three option buttons. This will designate which sound file to play.

2.	Then click the Play button. You must make sure that your computer is configured to support playing sound. This normally requires some type of sound card and speakers connected to a sound card jack in the back of your computer.


Declaring a Sound Function

The first step in declaring a sound function is to create an object that is to be the designated sound object. In the sample, the object AudioPlayer was created for this purpose. To create an object, simply click the Objects/New Object menu found in the Object Browser. A dialog will be displayed for you to name your object.

Once the object has been created, double-click on the object in the Object Browser to make it the "current object." This gives focus to the object and displays it in the Property and Method editors. In the Method Editor, you create a Function by clicking on the "Add New Method" button until you see a Declare Function template. Enter the following information to declare a sound function for your application:

Declare Function sndPlaySoundA Lib "Winmm" (ByVal file As String, ByVal opt As Long) As Long

Once you have a sound object with this sound function declared, you are ready to play a sound file.


Playing a Sound File

The sound function in this sample is designed to play a sound (.wav) file that is stored on your hard drive. Your application should know the name of the sound file and its directory location. To actually play the sound file, the following program code is required:

Dim result As long

Dim option As long

Dim sound_file As String

' Set the name of the sound file to play

sound_file = "c:\envelop\samples\apisound\thatsall.wav"

  	' Play the selected sound file

  	result = AudioPlayer.sndPlaySoundA(sound_file, option)

This is all there is to playing sound file from your application. The "option" parameter does not have to be configured, but must be passed to satisfy the sndPlaySound declaration statement.