Compartilhar via


MediaCollection.add method

[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 add method adds a new media item or playlist to the library.

Syntax

retVal = MediaCollection.add(
  path
)

Parameters

path [in]

String containing the path.

Return value

This method returns a Media object.

Remarks

This method loads an existing media item or playlist into the library, given a path to a file. This method does not move or change the file. This method fails if given an invalid local path, but digital media files are not checked for validity before they are added to the library.

This method accepts both static and auto playlist files. The PlaylistCollection.importPlaylist method can also be used to add a static playlist to the library.

To use this method, full access to the library is required. For more information, see Library Access.

Examples

The following Microsoft JScript example adds three media objects to the Windows Media Player media collection. The Player object was created with ID="Player".

// Adding a media object using a website.
Player.mediaCollection.add("https://www.proseware.com/Media/Laure.wma");

// Adding a media object from a local network.
// You must add an escape sequence of a backslash for 
// every original backslash.
Player.mediaCollection.add("\\\\yourservername\\Public\\Jeanne.wma");

// Adding a media object from a file on a local drive.
// Be sure to add appropriate escape sequences.
Player.mediaCollection.add("C:\\WMSDK\\WMPSDK\\docs\\samples\\media\\house.wma");

Requirements

Requirement Value
Version
Windows Media Player version 7.0 or later.
DLL
Wmp.dll

See also

Managing Playlists

Media Object

MediaCollection Object

MediaCollection.remove

PlaylistCollection.importPlaylist

Settings.mediaAccessRights

Settings.requestMediaAccessRights