I use a messagewindow class to receive the notify events as follows:
Private Class MessageWindow
Inherits Control
Public Event ItemFinished(ByVal result As PlayResult)
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case (m.Msg)
' The WM_ACTIVATEAPP message occurs when the application
' becomes the active application or becomes inactive.
Case MM_MCINOTIFY
' The WParam.ToInt32 identifies what is occurring.
'Note: mLParam.ToInt64 is DeviceID
Dim result As PlayResult
Select Case m.WParam.ToInt32()
Case MCI_NOTIFY_SUCCESSFUL
'The conditions initiating the callback function
have been met.
result = PlayResult.Successful
Case MCI_NOTIFY_ABORTED
' The device received a command that prevented
the current conditions for initiating the callback function from being met.
If a new command interrupts the current command and it also requests
notification, the device sends this message only and not
result = PlayResult.Aborted
Case MCI_NOTIFY_SUPERSEDED
result = PlayResult.Superseded
Case MCI_NOTIFY_FAILURE
' A device error occurred while the device was
executing the command.
result = PlayResult.DeviceFailure
Case Else
result = PlayResult.Unknown
End Select
'' Invalidate to get new text painted.
'Me.Invalidate()
If Not v_SetPositionFlag Then RaiseEvent
ItemFinished(result) Else v_SetPositionFlag = False
Exit Sub
End Select
MyBase.WndProc(m)
End Sub
End Class
--
Dennis in Houston
"Mark Denardo" wrote:
Does anyone have any good VB.NET example code that shows how to use the
NOTIFY option using the mciSendString API and then handle the return value.
The only examples I can find show the VB way using <Form>.hWnd
My program basically needs to start a media file and then be informed when
it has finished. Right now I have to set up a polling thread to check the
status of the playing media file, which works, but causes other parts of my
program to not be so neatly organized.
Also I noticed that when I call the SEEK command to set the position of an
already playing media file, it stops it. Is this the normal behavior or
perhaps I have something hidden in my code that is triggering it to stop.
For now when I call my Position method, I check to see if the program is
already playing, and if so, I follow my SEEK with a PLAY. That seems weird,
why even use the SEEK command then, why not just STOP and then PLAY the
media from the position point. What am I missing?