Using the Windows Media Player Control with Visual Basic

This section describes how to use the Windows Media Player 9 Series or later ActiveX control in applications created with Microsoft Visual Basic 6.0.

Getting Started

To add the Windows Media Player control to the toolbox, first select Components from the Project menu. In the Components dialog box, select the check box next to "Windows Media Player". At the bottom of the dialog box, confirm that the selected file is wmp.dll. After closing the dialog box, you can place an instance of the Windows Media Player control on your form in the usual ways.

You can set many control properties using the Properties window. To set some properties you must use the Windows Media Player Properties dialog box, which you open using the "(Custom)" item in the Properties window.

Object References

You use certain Player control properties to get references to particular objects. For example, the cdromCollection property returns a reference to a CdromCollection object. You must assign such a reference to a variable that you declared as the corresponding interface. In the case of the cdromCollection property, for example, you assign its return value to a variable of type IWMPCdromCollection.

Read the Interfaces topic in the Object Model Reference for C++ to identify which objects implement multiple interfaces. In those cases, you must declare an object variable as the highest-numbered interface documented in this SDK to have access to all of the properties and methods of that object. For example, you should assign the value of the Windows Media Player control currentMedia property to a variable declared as IWMPMedia3 to assure that you have access to the getAttributeCountByType and getItemInfoByType methods.

Note  The WindowsMediaPlayer object implements all of the properties and methods of the IWMPCore, IWMPCore2, IWMPCore3, IWMPPlayer, IWMPPlayer2, IWMPPlayer3, and IWMPPlayer4 interfaces. You do not need to declare separate variables for any of these interfaces. You can access all of their members using the name you assigned to your WindowsMediaPlayer instance.

In the Visual Basic Object Browser you will see many interfaces that are intended for private use by the Windows Media Player control, including some that support skin developers. You should use only the objects, properties, methods, and events that are documented in this SDK.

Additional Tips

  • The reference documentation shows JScript syntax. In JScript, arguments passed to methods are always enclosed in parentheses. In Visual Basic 6.0, arguments passed to methods that do not return a value must not be enclosed in parentheses.
  • Some properties or methods may not appear in the Auto List code-completion feature in the Visual Basic code editor. You can still use those members by typing their names exactly as they appear in this documentation.
  • Manage the visual appearance of the control using the uimode property. You can do so in two ways. You can use the Select a mode drop-down list in the Windows Media Player Properties dialog box, or you can type the correct value in the Properties window.

    In particular, do not use the visible property to hide the control; instead, assign the value "invisible" to the uimode property.

Related topics

Player Control Guide