Compartir a través de


IWMPMediaCollection::getByName 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 getByName method returns an IWMPPlaylist interface that provides access to media items with the specified name.

Syntax

public IWMPPlaylist getByName(
  System.String bstrName
);

Public Function getByName( _
  ByVal bstrName As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByName

Parameters

bstrName [in]

The System.String that is the specified name.

Return value

A WMPLib.IWMPPlaylist interface for the retrieved media items.

Remarks

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

There are two ways you ways you can retrieve an IWMPMediaCollection interface, and the behavior of the getByName method depends on which of those two ways you use. If you retrieve the interface by calling AxWindowsMediaPlayer.mediaCollection, then the getByName method returns all the media items in the library. However, if you retrieve the interface by calling IWMPLibrary.mediaCollection, then the getByName method returns only the audio items in the library that have the specified attribute and value.

Examples

The following example uses getByName to retrieve three items from the library. Each item is then appended to the current playlist. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

// In each case, use the name exactly as it appears in the library.
// Windows Media Player does not include file name extensions or file paths
// in the name. Internet URLs include the entire path, but not the 
// file name extension.

// Get an interface to a playlist that contains an Internet URL.
WMPLib.IWMPPlaylist one = player.mediaCollection.getByName("https://www.proseware.com/Media/Laure");

// Get an interface to a playlist that contains a file on a network server.
WMPLib.IWMPPlaylist two = player.mediaCollection.getByName("Jeanne");

// Get an interface to a playlist that contains a file on a local drive.
WMPLib.IWMPPlaylist three = player.mediaCollection.getByName("house");

// Append each item to the current playlist. Since each playlist retrieved
// using getByName contains one digital media item, use the get_Item
// method with an index of zero to reference that item.
player.currentPlaylist.appendItem(one.get_Item(0));
player.currentPlaylist.appendItem(two.get_Item(0));
player.currentPlaylist.appendItem(three.get_Item(0));

' In each case, use the name exactly as it appears in the library.
' Windows Media Player does not include file name extensions or file paths
' in the name. Internet URLs include the entire path, but not the 
' file name extension.

' Get an interface to a playlist that contains an Internet URL.
Dim one As WMPLib.IWMPPlaylist = player.mediaCollection.getByName("https://www.proseware.com/Media/Laure")

' Get an interface to a playlist that contains a file on a network server.
Dim two As WMPLib.IWMPPlaylist = player.mediaCollection.getByName("Jeanne")

' Get an interface to a playlist that contains a file on a local drive.
Dim three As WMPLib.IWMPPlaylist = player.mediaCollection.getByName("house")

' Append each item to the current playlist. Since each playlist retrieved
' using getByName contains one digital media item, use the Item
' property with an index of zero to reference that item.
player.currentPlaylist.appendItem(one.Item(0))
player.currentPlaylist.appendItem(two.Item(0))
player.currentPlaylist.appendItem(three.Item(0))

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#)

IWMPPlaylist Interface (VB and C#)