I am using Visual Basic Express 2010 and the AXwindowsmediaplayer PlayStateChange event does not appear to work in Windows 7. I put a break point in my code and can start, stop, pause the player and the event is never initiated. If I run this in XP or Vista it works. I even started a new project in VB express on the Windows 7 machine with nothing but a player and the event and it is never initiated. is there a work around for this? i have set a timmer but the event I am watching for, MPLib.WMPPlayState.wmppsMediaEnded, happens so quickly that the timmer never catches it
- Edited by Rattman Tuesday, November 02, 2010 10:22 PM
Welcome to MSDN forums!
I use Windows Media Player ActiveX control in Windows 7, and PlayStateChange event and StatusChange event all work fine. The sample code is as below.
The potential cause I think is that the Windows 7 you use is 64-bit system. You can try changing the Targeting CPU to “x86” instead of the default “Any CPU” in Compile configuration. The x64 systems can run x86 applications in 32-bit emulation (that is WOW64 mode).
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWindowsMediaPlayer1.URL = "D:\OneCode\OneCode\Submit Sample Ideas.wmv"
Private Sub AxWindowsMediaPlayer1_StatusChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.StatusChange
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
By the way, how to add this control to ToolBox
Right-click the Toolbox -> Choose item -> COM Components -> add “Windows Media Player“ component
Then you will see Windows Media Player control on Toolbox, drag&drop it to Form1, AxWindowsMediaPlayer1 object will be created.
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact firstname.lastname@example.org
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
- Proposed as answer by silent sojourner Monday, November 21, 2011 8:55 PM
I got a clean harddrive and installed a fresh copy of Windows 7 professional x86 from MSDN with all the uodates and Installed Visual Basic Express 2010 (That is all) and the Playstatechange does not work. This tells me the problem must be with windows 7. I cant imagine it being a hardware issue but I guess it is possible.
P.S. I am using a Lenovo T-60
I have developed some code that utilizes the imbedded media player and the Player.playstatechange event. The app works fine, both in development and install, on my Vista machine and if I compile the code in Vista it will work on the Windows 7 machine when installed. If I do any of the above on my windows 7 machine the Playstatechange event does not work.
I am able to recreate the issue on a fresh install of Windows 7 Professional x86 and fresh install of VB 2010 express. Nothing else installed on the machine. same problem happens.
I am using a Lenovo T60 could it be hardware driver issues? Is anyone else seeing this problem. A simple test is to open a blank 'Windows Form Application" and drop in an AxWindowsMediaPlayer1, a Button and a text box. Add the following code and run
the textbox should show the state change when you play a media file.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Find & Play random clip ' Find Auto Clip ' Dim Clip As String = vbNullString OpenFileDialog1.Filter = "Audio Files (*.mp3, *.wav, *.mid,*.wma) |*.mp3;*.wav;*.mid;*.wma" If OpenFileDialog1.ShowDialog = DialogResult.OK Then Clip = OpenFileDialog1.FileName Player1.URL = Clip End If End Sub Private Sub Player1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles Player1.PlayStateChange TextBox1.Text = e.newState End Sub End Class
The issue doesn’t seem to be reproducible using either VB.net or C#. Please make sure you are adding the right COM reference object(wmp.dll).
Are you seeing your event handler being called at all(put a breakpoint on the event handler method)?
Are you expecting a certain event to fire?
Confirm the event handler is set correctly in the designer.
1. Open the Windows Form and select the WMP control.
2. Right-click on the control and select properties.
3. On the properties panel, click on the lightning bolt icon and look for the events.
4. You should see the methods names for the property change
If you are expecting certain events to occur this could be the problem. The event system in WMP is asynchronous and not guaranteed to generate a specific event or that the events will occur in a specific order. , if there is a significant delay from when the event was generated and when it is processed the event that was delayed can be thrown out without your application to knowing about it. If you need more control of the media playback, you might want to look into an unmanaged c++ SDK such as DirectShow or MediaFoundation.
I run exactly into the same issue! I am using Visual C# Professional 2008 and tha PlayStateChance event does also not work on Windows 7. The same code works perfect on vista and xp, the version I compiled on Windows XP works also on all versions of windows...