473,416 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

mciSendString - NOTIFY & SEEK help needed

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
3 4953
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeroen van Vliet | last post by:
I made a program where wav files will be played from the database, with the full path.LIKE i = mciSendstring(open d:\sound.wav type waveaudio",0&,0,0) i = mciSendstring(play d:\sound.wav...
3
by: Dennis | last post by:
I am trying to use the Notify Flag to send a message when a song is finished playing. I got it to work by setting up a dummy window and overriding it's WndProc procedure then raising an event in...
5
by: Ted Shab | last post by:
Hi, I'm trying to come up with a relatively simple multi-master replication solution. This is for multiple databases that need to be discreet, and change relatively infrequently (10-30 updates...
0
by: kbodily | last post by:
Hi, I have this code in a dragdrop routine for a listview to get the duration of an mp3, where fPath is the path to the file that gets dropped Dim fname As String = Chr(34) + Trim(fPath) +...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
1
by: =?Utf-8?B?Q8Opc2Fy?= | last post by:
Could anyone tell me what am i doing bad? When i use the "MciSendString" always returns a big number instead 0 : What it says that there is an error, and so don't play the sound. Then...
1
by: _nabuchodonozor | last post by:
HI The mciSendString returns different value of tracks length than winamp. The value is longer about 20 seconds and I don't know why. Here is a code: public void SetTime() // I tried to set...
1
by: bajunaid | last post by:
Hi.. I'm trying to use mciSendString to play MP3 files and record WAV using mciSendString.. I did it successfully in a C# windowsApplicaton.. But when I move the same cod to my ASP file.. It...
4
by: DR | last post by:
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.