Article ID: 247036
Article Last Modified on 6/29/2004
APPLIES TO
- Microsoft Visual FoxPro 5.0a
- Microsoft Visual FoxPro 6.0 Professional Edition
This article was previously published under Q247036
SUMMARY
This article demonstrates how to add sound, or .wav files, to a form.
MORE INFORMATION
Although you can use the SET BELL TO command to play a waveform file, you do not have control over the file once it starts. That is, you cannot stop, pause, or resume the waveform file. By using the Microsoft Multimedia Control version 6, you can play a waveform file when the form is opened or whenever you wish to add sound.
Because you have control over the waveform file, it is not necessary to have the Multimedia control visible. All actions can be controlled through code.
- In the Tools menu, under Options, click the Controls tab. Click ActiveX Controls, scroll down the list and select Microsoft Multimedia Control version 6, and then click OK.
- Create a new form.
- On the Form Controls toolbar, click the View Classes button, and then select ActiveX Controls.
- Click the Multimedia control and add it to the form.
- Select the Multimedia control and change the Name property to MCI. Change the Visible property to .F.
Open the Init event of the Multimedia control and add the following code:
* Set properties needed by MCI to open. THISFORM.MCI.NOTIFY = .T. && Pause THISFORM.MCI.WAIT = .T. THISFORM.MCI.Shareable = .F. THISFORM.MCI.DeviceType = "WaveAudio" THISFORM.MCI.RecordEnabled = .T. THISFORM.MCI.RecordMode = 0 THISFORM.MCI.StopEnabled = .T. THISFORM.MCI.FileName = GETFILE("wav") * Open the MCI WaveAudio device. THISFORM.MCI.COMMAND = "Open" THISFORM.MCI.COMMAND = "Play"
- Add a Command button and change the caption to Stop.
In the click event of the Stop button, add this code:
IF THIS.CAPTION="Stop" THISFORM.MCI.COMMAND = "Stop" THIS.CAPTION="Restart" ELSE THISFORM.MCI.COMMAND = "Play" THIS.CAPTION="Stop" ENDIF
In the Destroy event of the form, add this code:
THISFORM.MCI.COMMAND = "Close"
- Add another Command button and change the caption to Rewind.
In the click event of the Rewind button, add this code:
THISFORM.MCI.COMMAND = "Seek" THISFORM.MCI.COMMAND = "Play"
This is just to show how you can replay the waveform file.
Run the form. If you have a valid waveform file, enter the path and name in the Thisform.MCI.FileName property in the Init event of the control instead of using the GETFILE() function. Click on the Stop button to stop the waveform file, then click on the Restart button to resume playing the waveform file at the same position.
(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation.
Keywords: kbhowto kbcodesnippet kbcontainer kbctrl KB247036