Results 1 to 4 of 4

Thread: [RESOLVED] WaveOut API and Progressbar

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] WaveOut API and Progressbar

    I'm working on a sound project using waveIn and waveOut APIs. I can record into a buffer (waveIn) and then play back from the buffer (waveOut) - no problem here. Where I am having a problem is how to display a progressbar showing the time remaining. This is like what you would see on many sound players as the sound is being played a progressbar moves left to right showing how much has been played and how much there is to go before the sound stops.

    My assumption is that there might be some value you can get from an API that represents either the time duration left or perhaps the position within the sound buffer. Using this value, which ever one it may be, I can then calculate the movement of the progressbar.

    There is another API, mciSendString, which returns the position within the sound buffer that can be used for this purpose. I would use the mciSendString API except for one thing. I have not been able to find how to use mciSendString to record and play from a buffer (buffer meaning a user defined array) and therefore cannot use mciSendString to calculate the progressbar. Since I am able to record and play from a buffer using waveIn/waveOut APIs then my only hope for now is to find out how to get the return value I need.

    Anyone have any ideas how to get this return value from waveOut?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: WaveOut API and Progressbar

    waveOutGetPosition perhaps?

    Code:
    Private Const MMSYSERR_NOERROR As Long = 0      'no error
    Private Const TIME_MS          As Long = &H1    'time in milliseconds
    
    Private Type MMTIME
        wType As Long   'Time format.
        ms    As Long   'Number of milliseconds. Used when wType is TIME_MS.
    End Type
    
    Private Declare Function waveOutGetPosition Lib "winmm.dll" (ByVal hwo As Long, ByRef pmmt As MMTIME, ByVal cbmmt As Long) As Long
    
    Private Function GetPositionInMilliSecs(ByVal hWaveOut As Long) As Long
        Dim MMT As MMTIME
    
        MMT.wType = TIME_MS
        If waveOutGetPosition(hWaveOut, MMT, LenB(MMT)) = MMSYSERR_NOERROR Then
            If MMT.wType = TIME_MS Then GetPositionInMilliSecs = MMT.ms
        End If
    End Function
    Last edited by Bonnie West; May 22nd, 2013 at 03:15 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: WaveOut API and Progressbar

    Your code example looks correct except I get a return error 1 which is:

    MMSYSERR_ERROR Unspecified Error

    I know that hWaveOut is correct because it is the same value I get when I open the device using...

    lngReturn = waveOutOpen(hWaveOut, lngDevOutIndex, VarPtr(WaveFormat), 0, 0, 0)

    ...so I know that's not the problem

    In the above lngReturn = 0 and hWaveOut = 2010632 and that's the same value in hWaveOut argument of waveOutGetPosition

    Also, I know the Time format is supported because after the function is called .wType = 1 which is TIME_MS and Micro Soft says that if the format is not supported you will get a substitute format
    Last edited by jmsrickland; May 22nd, 2013 at 05:48 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: WaveOut API and Progressbar

    OK, I got it to work. The Type structure was incorrect. I was using the one that I got from VB's API Viewer which is incorrect. After I corrected the Type structure it worked.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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