Windows Media Player 11 SDK Using the Windows Media Player 7 or Later Object ModelĀ 

Windows Media Player SDK banner art

Previous Next

Using the Windows Media Player 7 or Later Object Model

Most of the tasks you may have been performing using the Windows Media Player 6.4 ActiveX control object model will require a new approach. In many cases, the names of the properties, methods, and events have changed in the Windows Media Player 7 or later object model. For instance, to specify the file path in the version 6.4 object model, you set the Player6.FileName property:

  

When using the Windows Media Player 7 or later object model, you must set the *Player.*URL property:

  

Alternatively, using the 10 object model, you can obtain a Media object from the library, and then set the Player.currentMedia property:

  

Much of the functionality in the Windows Media Player 7 or later object model is accessed through the object hierarchy. As the previous example showed, you can obtain a Playlist object by using the getAll method of the mediaCollection object, which is accessed through the root Player object. You can then obtain a particular Media object from the Playlist object by using the item method of the Playlist object. There are five additional methods accessible through the mediaCollection object that return a Playlist object; each method allows you to retrieve the object based on specific criteria, like genre or album.

The hierarchical structure of the Windows Media Player 7 or later ActiveX control object model provides a more logical approach to organizing the properties, methods, and events available for your use. All the functionality for the Player controls is contained in the Controls object, all the functionality for the Player network connection is contained in the Network object, and so forth. For example, to start content playing using the version 6.4 object model, you use the Player6.Play method:

  

When using the Windows Media Player 7 or later object model, you must access the Play method by using the Controls object:

  

The depth of the object model, however, can lead to very long script statements:

  

Statements like the preceding one can be made much simpler and more readable by working with individual named objects. The following example replaces the preceding code statement with syntax using separate object variables:

  

This coding style requires more lines of script, but is much easier to follow, especially with the added comments. There is another advantage: the currentPlaylist object is easy to reuse because it is stored in the variable pl.

Many of the properties, methods, and events in the Windows Media Player 7 or later object model set or retrieve different values, or return values of a different type or number, compared to corresponding functionality in the version 6.4 object model. For instance, when Player6.openState retrieves 2, that value corresponds to the Visual Basic constant nsLoadingNSC, meaning the Player is loading a station file with a .nsc file name extension. But when the Windows Media Player 7 or later object model property Player.openState retrieves 2, that value corresponds to the state PlaylistLocating, meaning Windows Media Player is attempting to locate a playlist. Additionally, the Player6.openState property can retrieve seven different values, while the Windows Media Player 7 or later Player.openState property can retrieve 22 different values. Be sure to refer to the Object Model Reference for Scripting section of the Windows Media Player SDK when revising code to use a different object model version.

See Also

Previous Next