Partager via


About the MediaCollection and Media Objects

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The MediaCollection and Media objects govern the media collection, which defines the locations of digital media files that Windows Media Player can access. You get the MediaCollection object from the mediaCollection property of the Player object. The mediaCollection property returns the MediaCollection object. You can only access the properties of the MediaCollection object after you have created it. For example, to add a Media object (a song), use the following code:

player.mediacollection.add('laure.wma');

You have added the file laure.wma to the media collection.

You can get the current Media object by using the currentMedia property of the Player. For example, this code gets the duration property of the current Media object:

myduration = player.currentmedia.duration;

There are many ways to get a Media object so that you can access its properties. For example, if you want to access the duration property of the current media, each of the following lines of code could be used.

To get the duration of the currently playing media:

player.currentMedia.duration;

To get the duration of the current media in a playlist:

player.controls.currentItem.duration;

To get the duration of the third media item in a playlist:

player.currentPlaylist.item(2).duration;

To get the duration of the third media item in a "Jazz" genre:

player.mediaCollection.getByGenre("jazz").item(2).duration;

To get the duration of the third media item in the second playlist:

player.playlistCollection.getAll.item(1).item(2).duration; 

Media Object

MediaCollection Object

Player Object Model for Scripting Languages