none
playstatechange not working in windows 7

    Question

  • 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   
    Scott Berry
    • Edited by Rattman Tuesday, November 02, 2010 10:22 PM
    Monday, November 01, 2010 11:14 PM

All replies

  • More details: I tried compliling the Application on Vista and it works on all system but when I compile on Windows 7  Machine it only works on Vista and XP.  What would cause this to happen


    Scott Berry
    Tuesday, November 02, 2010 10:18 PM
  • Hi Rattman,

     

    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"

        End Sub

     

        Private Sub AxWindowsMediaPlayer1_StatusChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.StatusChange

            MessageBox.Show("StatusChange")

        End Sub

     

        Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange

            MessageBox.Show("PlayStateChange")

        End Sub

     

    End Class

     

    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.

     

     

    Best regards,

    Martin Xie

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    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.
    Wednesday, November 03, 2010 10:08 AM
  • 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


    Scott Berry
    Friday, November 05, 2010 12:56 PM
  • 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
    • Edited by Rattman Friday, November 05, 2010 2:21 PM
    • Merged by Martin_XieModerator Monday, November 08, 2010 1:34 AM Merge them to keep in the same one topic.
    Friday, November 05, 2010 1:25 PM
  • You will also need to add an 'OpenFileDialog1'  and change the name of the player to just Player1 
    Scott Berry
    Friday, November 05, 2010 2:18 PM
  • 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).

    Some questions:

    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

    http://msdn.microsoft.com/en-us/library/dd562852(v=VS.85).aspx

     

    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.

    Chis Cooper

    Tuesday, November 09, 2010 9:17 PM
  • 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...
    Friday, February 18, 2011 11:20 AM
  • TiniFAx,

    Nice you say that, do you expect some help, than create your one question and don't hi jack the one from somebody else.

     


    Success
    Cor
    Friday, February 18, 2011 12:05 PM
  • Actually Tintifax73  i am glad to hear i am not the only one having this issue. I still have to compile in Vista or Xp everytime I update my code. Still hoping someday this gets fixed

     


    Scott Berry
    Tuesday, November 22, 2011 3:36 AM
  • I have check all this and everything runs fine if I compile in Vista or XP. It only fails when I compile in Win 7.

     


    Scott Berry
    Tuesday, November 22, 2011 3:41 AM