[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?
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
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
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.