This class allows you to interact with WAV or MIDI files without using the Microsoft Multimedia Control.
Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CWAVMID class. |
FileName | Property | Get the name of the file. |
Length | Property | Get the play length of the sound file. |
Position | Property | Get the position of the sound file. |
Class_Terminate | Terminate | Close the MCI resource. |
OpenWAV | Method | Open the WAV file. The filename property should be set before calling this procedure. |
Pause | Method | Pause the WAV file. |
Play | Method | Play the WAV file. The OpenWav procedure must be called before this procedure. |
Record | Method | Record a WAV file. The FileName property must be defined before calling this method. This method saves the recording to the file specified in FileName. |
Rewind | Method | Rewind the WAV file. |
StopPlay | Method | Stop playing the WAV file. |
CloseWAV | Method | Close the WAV file. |
' Example of the CWAVMID Class ' ' To try this example, do the following: ' 1. Create a new form ' 2. Add a command button called 'cmdPlay' ' 3. Add a command button called 'cmdStop' ' 4. Add a command button called 'cmdPause' ' 5. Add a command button called 'cmdRewind' ' 6. Add a command button called 'cmdRecord' ' 7. Paste all the code from this example to the new form's module ' 8. Run the form ' This example assumes that the sample files are located in the folder named by the following constant. Private Const mcstrSamplePath As String = "C:\TVSBSamp" Private mclsWavMid As CWAVMID Private Sub cmdPause_Click() If mclsWavMid Is Nothing Then CreateWavMidObject "Play" End If ' Pause playback mclsWavMid.Pause End Sub Private Sub cmdPlay_Click() If mclsWavMid Is Nothing Then CreateWavMidObject "Play" End If ' Play the file mclsWavMid.Play End Sub Private Sub cmdRewind_Click() If mclsWavMid Is Nothing Then CreateWavMidObject "Play" End If ' Rewind the file mclsWavMid.Rewind End Sub Private Sub cmdStop_Click() If mclsWavMid Is Nothing Then CreateWavMidObject "Play" End If ' Stop the playback mclsWavMid.StopPlay End Sub Private Sub CreateWavMidObject(ByRef strRecordOrPlay As String) Set mclsWavMid = New CWAVMID If strRecordOrPlay = "Play" Then ' set the filename mclsWavMid.FileName = mcstrSamplePath & "\test.wav" ' open the file mclsWavMid.OpenWAV Else mclsWavMid.FileName = mcstrSamplePath & "\testYourRecording.wav" End If ' Set the button captions cmdRecord.Caption = "Record" cmdPlay.Caption = "Play" cmdPause.Caption = "Pause" cmdStop.Caption = "Stop" cmdRewind.Caption = "Rewind" End Sub Private Sub cmdRecord_Click() Dim lngLastPointer As Long If mclsWavMid Is Nothing Then CreateWavMidObject "Record" End If 'Save the last mousepointer in use lngLastPointer = Screen.MousePointer 'Show hourglass Screen.MousePointer = vbHourglass 'Record for 5 seconds mclsWavMid.Record (5000) 'Close when we are done mclsWavMid.CloseWAV 'Reset mousepointer Screen.MousePointer = lngLastPointer End Sub Private Sub Form_Load() Me.cmdPause.Caption = "Pause" Me.cmdPlay.Caption = "Play" Me.cmdStop.Caption = "Stop" Me.cmdRecord.Caption = "Record" Me.cmdRewind.Caption = "Rewind" End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP