Search code examples
vb.netwindows-media-player

Is it possible to create a new instance of the Windows Media Player class in VB 2008 code?


I don't want a Windows Media Player control on my form. I'm making an alarm clock. I have tried this:

Friend WithEvents WindowsMediaPlayer As New Microsoft.Win32.

But I don't see a Windows Media Player member.

Thank you.

I also asked on the MSDN VB Forum.


Solution

  • Your snippet is not complete. But nothing good will happen when you start with "Microsoft.Win32.". Begin with Project + Add Reference, Browse tab and select c:\windows\system32\wmp.dll. That adds a com interop wrapper with the namespace name "WMPLib". IntelliSense will now spring to life and show you the classes in that namespace. Make it resemble this:

    Public Class Form1
      Friend WithEvents player As WMPLib.WindowsMediaPlayer
    
      Public Sub New()
        InitializeComponent()
        player = New WMPLib.WindowsMediaPlayer
      End Sub
    
      Private Sub player_StatusChange() Handles player.StatusChange
        ' A sample event handler...
      End Sub
    
    End Class