다음을 통해 공유


IWMPMediaCollection::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

public IWMPMedia add(
  System.String bstrURL
);

Public Function add( _
  ByVal bstrURL As System.String _
) As IWMPMedia
Implements IWMPMediaCollection.add

Parameters

bstrURL [in]

A System.String that is the URL that specifies the location of the media item or playlist.

Return value

The WMPLib.IWMPMedia interface for the added item or playlist.

Remarks

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

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

Before calling this method, you must have full access to the library. For more information, see Library Access.

Examples

The following example adds three media objects to the Windows Media Player media collection. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named 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.
// Either use the @ symbol to denote a quoted string literal or add additional
// backlashes as an escape for every original backslash.
player.mediaCollection.add(@"\\yourservername\Public\Jeanne.wma");

// Adding a media object from a file on a local drive.
// Either use the @ symbol to denote a quoted string literal or add additional
// backlashes as an escape for every original backslash.
player.mediaCollection.add(@"C:\WMSDK\WMPSDK\samples\media\house.wma");

' Adding a media object using a website.
player.mediaCollection.add("http:'www.proseware.com/Media/Laure.wma")

' Adding a media object from a local network.
player.mediaCollection.add("\\yourservername\Public\Jeanne.wma")

' Adding a media object from a file on a local drive.
player.mediaCollection.add("C:\WMSDK\WMPSDK\samples\media\house.wma")

Requirements

Requirement Value
Version
Windows Media Player 9 Series or later
Namespace
WMPLib
Assembly
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

See also

IWMPMediaCollection Interface (VB and C#)

IWMPMediaCollection.remove (VB and C#)

IWMPPlaylistCollection.importPlaylist (VB and C#)