|
-
Apr 4th, 2001, 01:57 PM
#1
Thread Starter
Lively Member
Is there a way to record .wav file & at the same time can detect if playing back of the wav file has finished ? The detection of the playing back can be coded in a true or false satement.
-
Apr 4th, 2001, 06:45 PM
#2
Here's how you can record a WAV file.
Code:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub cmdRecord_Click()
mciSendString "open new type waveaudio Alias record", 0&, 0, 0
mciSendString "record record", 0&, 0, 0
End Sub
Private Sub cmdSave_Click()
mciSendString "stop record", 0&, 0, 0
mciSendString "save record C:\Windows\Desktop\MyWav.wav", 0&, 0, 0
mciSendString "close record", 0&, 0, 0
End Sub
-
Apr 5th, 2001, 12:27 AM
#3
Thread Starter
Lively Member
But how to detect if the .wav has finished playing back ?
-
Apr 6th, 2001, 07:12 AM
#4
PowerPoster
Code:
'To play a music file
'Assuming that you have executed Megatron's code
Private Sub cmdPlay_Click()
mciSendString "open C:\Windows\Desktop\MyWav.wav type waveaudio Alias record", 0&, 0, 0
mciSendString "Play Record Notify", 0&,0, cmdPlay.hwnd
End Sub
Private Sub Form_Load()
'Set a hook for intercepting messages to cmdPlay
OldProc = SetWindowLong(cmdPlay.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong cmdPlay.hwnd, GWL_WNDPROC, OldProc
End Sub
'in a standard module
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const MM_MCINOTIFY = &H3B9
Global Oldproc As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As LongEnd Sub
If uMsg = MM_MCINOTIFY Then
'do whatever
Debug.Print "Song Playback Completed"
Else
CallWindowProc OldProc, cmdPlay.hwnd, uMsg, wParam, lParam
End If
End Function
This code may have errors as I have not tested it. I am just wriring what I reember on top of my mind.
-
Apr 6th, 2001, 09:13 AM
#5
Thread Starter
Lively Member
Thanks for replying i alter some of your code. But i noticed that this mcisendstring command do not return until it has finished playing the wav. Is there a way i can call the mcisendstring to play the wav & also allow the exectuion of the remaining code to continue. I mean i was hoping for this mcisendstring to be asynchronous.
-
Apr 6th, 2001, 09:33 AM
#6
Thread Starter
Lively Member
f = mciSendString("open " & sWAV & " type waveaudio alias voice1", 0&, 0, 0)
f = mciSendString("play voice1", 0&, 0, 0)
I dont know why the VB complier says that the line' f = mciSendString("play voice1", 0&, 0, 0)' is out of context. What is meant by this & can it be solved?
-
Apr 6th, 2001, 09:38 AM
#7
PowerPoster
Try using the notify keyword along with the code that I have given. It should work asynchronously. Does the first line execute perfectly or does it reurn any error?
-
Apr 6th, 2001, 03:21 PM
#8
mciSendString("play voice1", 0&, 0, 0)
Shouldn't you change the last argument to the handle of the Form you want to notify?
-
Apr 6th, 2001, 09:35 PM
#9
PowerPoster
Yes, definitely you need to set the last argument as a handle to the window that will recieve the notification . I heve used the command button for this purpose and set a hook to trap the MM_MCINOTIFY message. Thats what I have done in the my code posted above.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|