Results 1 to 4 of 4

Thread: Playing WAV file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Playing WAV file

    I need my app to play a simple wav file to notify user of certain things.
    I'm currently using the "sndPlaySoundA" API, but it doesn't allow me to set the volume that it must play the file at.

    Is there a way to set the volume for this API or another easy way to play a wav file and set the volume JUST for that specific file? (so that it doesn't change the system volume)
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Playing WAV file

    Anyone??
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  3. #3
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: Playing WAV file

    Cant rember where i found this (probly here at the forums) but i use this with mp3s.

    In a modual.
    VB Code:
    1. Option Explicit
    2.  
    3. Const MMSYSERR_NOERROR = 0
    4. Const MAXPNAMELEN = 32
    5. Const MIXER_LONG_NAME_CHARS = 64
    6. Const MIXER_SHORT_NAME_CHARS = 16
    7. Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
    8. Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
    9. Const MIXER_SETCONTROLDETAILSF_VALUE = &H0&
    10. Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
    11. Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = &H4
    12. Const MIXERCONTROL_CONTROLTYPE_VOLUME = &H50030001
    13.  
    14. Private Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, _
    15.     ByVal uMxId As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, _
    16.     ByVal fdwOpen As Long) As Long
    17. Private Declare Function mixerGetLineInfo Lib "winmm.dll" Alias _
    18.     "mixerGetLineInfoA" (ByVal hmxobj As Long, pmxl As MIXERLINE, _
    19.     ByVal fdwInfo As Long) As Long
    20. Private Declare Function mixerGetLineControls Lib "winmm.dll" Alias _
    21.     "mixerGetLineControlsA" (ByVal hmxobj As Long, pmxlc As MIXERLINECONTROLS, _
    22.     ByVal fdwControls As Long) As Long
    23. Private Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj _
    24.     As Long, pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Long) As Long
    25. Private Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As Long) As Long
    26. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    27.     (Destination As Any, Source As Any, ByVal Length As Long)
    28. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
    29.     ByVal dwBytes As Long) As Long
    30. Private Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
    31. Private Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long
    32.  
    33. Private Type MIXERCONTROL
    34.     cbStruct As Long
    35.     dwControlID As Long
    36.     dwControlType As Long
    37.     fdwControl As Long
    38.     cMultipleItems As Long
    39.     szShortName As String * MIXER_SHORT_NAME_CHARS
    40.     szName As String * MIXER_LONG_NAME_CHARS
    41.     lMinimum As Long
    42.     lMaximum As Long
    43.     reserved(10) As Long
    44. End Type
    45.  
    46. Private Type MIXERCONTROLDETAILS
    47.     cbStruct As Long
    48.     dwControlID As Long
    49.     cChannels As Long
    50.     item As Long
    51.     cbDetails As Long
    52.     paDetails As Long
    53. End Type
    54.  
    55. Private Type MIXERCONTROLDETAILS_UNSIGNED
    56.     dwValue As Long
    57. End Type
    58.  
    59. Private Type MIXERLINE
    60.     cbStruct As Long
    61.     dwDestination As Long
    62.     dwSource As Long
    63.     dwLineID As Long
    64.     fdwLine As Long
    65.     dwUser As Long
    66.     dwComponentType As Long
    67.     cChannels As Long
    68.     cConnections As Long
    69.     cControls As Long
    70.     szShortName As String * MIXER_SHORT_NAME_CHARS
    71.     szName As String * MIXER_LONG_NAME_CHARS
    72.     dwType As Long
    73.     dwDeviceID As Long
    74.     wMid  As Integer
    75.     wPid As Integer
    76.     vDriverVersion As Long
    77.     szPname As String * MAXPNAMELEN
    78. End Type
    79.  
    80. Private Type MIXERLINECONTROLS
    81.     cbStruct As Long
    82.     dwLineID As Long
    83.     dwControl As Long
    84.     cControls As Long
    85.     cbmxctrl As Long
    86.     pamxctrl As Long
    87. End Type
    88.  
    89. ' Set the master volume level.
    90. '
    91. ' VolumeLevel is the level value in percentage (0 = min, 100 = max)
    92. ' Returns True if successful
    93.  
    94. Function SetVolume(VolumeLevel As Long) As Boolean
    95.     Dim hmx As Long
    96.     Dim uMixerLine As MIXERLINE
    97.     Dim uMixerControl As MIXERCONTROL
    98.     Dim uMixerLineControls As MIXERLINECONTROLS
    99.     Dim uDetails As MIXERCONTROLDETAILS
    100.     Dim uUnsigned As MIXERCONTROLDETAILS_UNSIGNED
    101.     Dim RetValue As Long
    102.     Dim hmem As Long
    103.  
    104.     ' VolumeLevel value must be between 0 and 100
    105.     If VolumeLevel < 0 Or VolumeLevel > 100 Then GoTo error
    106.    
    107.     ' Open the mixer
    108.     RetValue = mixerOpen(hmx, 0, 0, 0, 0)
    109.     If RetValue <> MMSYSERR_NOERROR Then GoTo error
    110.    
    111.     ' Initialize MIXERLINE structure and call mixerGetLineInfo
    112.     uMixerLine.cbStruct = Len(uMixerLine)
    113.     uMixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
    114.     RetValue = mixerGetLineInfo(hmx, uMixerLine, _
    115.         MIXER_GETLINEINFOF_COMPONENTTYPE)
    116.     If RetValue <> MMSYSERR_NOERROR Then GoTo error
    117.    
    118.     ' Initialize MIXERLINECONTROLS strucure and
    119.     ' call mixerGetLineControls
    120.     uMixerLineControls.cbStruct = Len(uMixerLineControls)
    121.     uMixerLineControls.dwLineID = uMixerLine.dwLineID
    122.     uMixerLineControls.dwControl = MIXERCONTROL_CONTROLTYPE_VOLUME
    123.     uMixerLineControls.cControls = 1
    124.     uMixerLineControls.cbmxctrl = Len(uMixerControl)
    125.    
    126.     ' Allocate a buffer to receive the properties of the master volume control
    127.     ' and put his address into uMixerLineControls.pamxctrl
    128.     hmem = GlobalAlloc(&H40, Len(uMixerControl))
    129.     uMixerLineControls.pamxctrl = GlobalLock(hmem)
    130.     uMixerControl.cbStruct = Len(uMixerControl)
    131.     RetValue = mixerGetLineControls(hmx, uMixerLineControls, _
    132.         MIXER_GETLINECONTROLSF_ONEBYTYPE)
    133.     If RetValue <> MMSYSERR_NOERROR Then GoTo error
    134.            
    135.     ' Copy data buffer into the uMixerControl structure
    136.     CopyMemory uMixerControl, ByVal uMixerLineControls.pamxctrl, _
    137.         Len(uMixerControl)
    138.     GlobalFree hmem
    139.     hmem = 0
    140.  
    141.     uDetails.item = 0
    142.     uDetails.dwControlID = uMixerControl.dwControlID
    143.     uDetails.cbStruct = Len(uDetails)
    144.     uDetails.cbDetails = Len(uUnsigned)
    145.    
    146.     ' Allocate a buffer in which properties for the volume control are set
    147.     ' and put his address into uDetails.paDetails
    148.     hmem = GlobalAlloc(&H40, Len(uUnsigned))
    149.     uDetails.paDetails = GlobalLock(hmem)
    150.     uDetails.cChannels = 1
    151.     uUnsigned.dwValue = CLng((VolumeLevel * uMixerControl.lMaximum) / 100)
    152.     CopyMemory ByVal uDetails.paDetails, uUnsigned, Len(uUnsigned)
    153.    
    154.     ' Set new volume level
    155.     RetValue = mixerSetControlDetails(hmx, uDetails, _
    156.         MIXER_SETCONTROLDETAILSF_VALUE)
    157.     GlobalFree hmem
    158.     hmem = 0
    159.     If RetValue <> MMSYSERR_NOERROR Then GoTo error
    160.    
    161.     mixerClose hmx
    162.     ' signal success
    163.     SetVolume = True
    164.     Exit Function
    165.    
    166. error:
    167.     ' An error occurred
    168.    
    169.     ' Release resources
    170.     If hmx <> 0 Then mixerClose hmx
    171.     If hmem Then GlobalFree hmem
    172.     ' signal failure
    173.     SetVolume = False
    174.  
    175. End Function


    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Playing WAV file

    Thanks for the reply but it looks to me like that sets the master volume, which is not what I want to do. I just want to change the volume at which my file is played.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width