Module: Multimedia in Category General VBA/VB6 : Multimedia from Total Visual SourceBook

Routines for working with multimedia devices in VB6 and VBA with 32 and 64-bit Windows API calls.

The module contains miscellaneous multimedia functions dealing with waveform audio files. The routines allow you to play or stop playing Windows .WAV files, to get and set the volume levels for wave devices, and to determine whether your user's machine supports waveform audio.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modMultimedia module.
CanPlayWaveData Procedure Determine if there is a device capable of playing wave files.
dblToLong Procedure Perform an unsigned conversion from a double to a long integer value. This function correctly handles doubles greater than 2,147,483,647 and less than or equal to 4,294,967,295.
HiWord Procedure Get the high integer of the passed long.
IntToLong Procedure Convert an integer value to a long integer value, treating the integer as unsigned.
LongToInt Procedure Perform an unsigned conversion from a long value to an integer value.
LoWord Procedure Get the low integer of the passed long.
MakeLong Procedure Combine two words (integers) into a long. This routine correctly handles negative input values.
WaveGetCurrentVolume Procedure Get the volume level (overall, left and right) settings for waveform audio devices. Note that the values for the Left and Right channel are modified by this procedure. This means that you should examine the values of the passed variables after calling the function. Do not pass a literal or constant as the lngLeft or lngRight arguments, since they cannot be modified.
WavePlaySound Procedure Play a .wav file.
WaveSetCurrentVolume Procedure Set the left and right stereo volume levels for a waveform audio device. The settings should be set to values between 0 and 65535. To change the balance between the left and right channels, use different values for each. Some audio devices may not be able to select the level you specify and will use the closest available value.
WaveTerminateSound Procedure Terminate a sound immediately. Use this to stop a waveform audio sound that is playing asynchronously, or in a loop.
' Example of the modMultimedia module
'
' To use this example:
' 1. Create a new form.
' 2. Create a command button called cmdTest
' 3. Create a command button called cmdPlay
' 4. Create a command button called cmdStop
' 5. Create a command button called cmdIncreaseVol
' 6. Create a command button called cmdDecreaseVol
' 7. Paste the entire contents of this module into the new form's module.

' This example assumes that the sample files are located in the folder named by the following constant.
Private Const mcstrSamplePath As String = "C:\Total Visual SourceBook 2013\Samples\"

Private Sub cmdDecreaseVol_Click()
  Dim lngLeft As Long
  Dim lngRight As Long
  Dim lngVolume As Long

  ' Get current channel settings
  lngVolume = WaveGetCurrentVolume(lngLeft, lngRight)

  ' Decrease left and right channels equally
  WaveSetCurrentVolume lngLeft - 1000, lngRight - 1000

End Sub

Private Sub cmdIncreaseVol_Click()
  Dim lngLeft As Long
  Dim lngRight As Long
  Dim lngVolume As Long

  ' Get current channel settings
  lngVolume = WaveGetCurrentVolume(lngLeft, lngRight)

  ' Increate left and right channels equally
  WaveSetCurrentVolume lngLeft + 1000, lngRight + 1000

End Sub

Private Sub cmdPlay_Click()
  Dim strWave As String

  strWave = mcstrSamplePath & "test.wav"
  ' Play a sample wave file
  WavePlaySound strWave, mmpfSND_ASYNC

End Sub

Private Sub cmdStop_Click()
  ' Stop an asynchronous wave file while it is playing
  WaveTerminateSound
End Sub

Private Sub cmdTest_Click()
  Dim lngLeft As Long
  Dim lngRight As Long
  Dim lngVolume As Long

  ' Test CanPlayWaveData
  If Not CanPlayWaveData() Then
    MsgBox "No wave-capable devices found"
  Else

    ' Get current channel volume levels
    lngVolume = WaveGetCurrentVolume(lngLeft, lngRight)

    Debug.Print "-----------"
    Debug.Print "Left volume: " & lngLeft
    Debug.Print "Right volume: " & lngRight
    Debug.Print "Total volume: " & lngVolume

  End If

End Sub

Total Visual SourceBook 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!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"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

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS