Microsoft KB Archive/247036

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 13:50, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


How To Add Sound to Form Using the Microsoft Multimedia Control

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.

  1. 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.
  2. Create a new form.
  3. On the Form Controls toolbar, click the View Classes button, and then select ActiveX Controls.
  4. Click the Multimedia control and add it to the form.
  5. Select the Multimedia control and change the Name property to MCI. Change the Visible property to .F.
  6. 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"
                        
  7. Add a Command button and change the caption to Stop.
  8. 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
  9. In the Destroy event of the form, add this code:

    THISFORM.MCI.COMMAND = "Close"
                        
  10. Add another Command button and change the caption to Rewind.
  11. 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