mciSendString - NOTIFY & SEEK help needed

  • Thread starter Thread starter Mark Denardo
  • Start date Start date
M

Mark Denardo

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?
 
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, the problem I'm having is how to set up and use the callback.

For example, what I see in the VB examples I found is a PLAY command like
so:

mciSendString("PLAY " & Alias & " NOTIFY", Nothing, 0, gHW)

where gHW is a Long, and somehow they are referencing it with Me.hWnd, which
must be something from VB and apparently not proper in VB.NET. I would
assume I would be using a delegate with AddressOf, but this type of callback
is foreign to me. Can you show me all the pieces I need to set up this
callback?

Mark
 
Below is the string I use to start playing a file:

mciSendString("PLAY " + AliasName + " FROM " + Value.ToString() + " NOTIFY",
Nothing, 0, MsgWindow.Handle)

MsgWindow is an instantiated class of the MsgWindow that I posted previously.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top