By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

mciSendString - NOTIFY & SEEK help needed

P: n/a
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?


Nov 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?


Nov 23 '05 #2

P: n/a
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
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
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?


Nov 23 '05 #3

P: n/a
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.

--
Dennis in Houston
"Mark Denardo" wrote:
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
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
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?



Nov 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.