Windows Media Player 11 SDK IWMPMediaCollection.getByName (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPMediaCollection.getByName (VB and C#)

The getByName method returns an IWMPPlaylist interface that provides access to media items with the specified name.

  

Parameters

bstrName

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.

Example Code

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 extensions or file paths
' in the name. Internet URLs include the entire path, but not the 
' file 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))

FakePre-1297c0c09e904feeb6ce57f4fd51939b-bb9870dacedc49a5bc4fcfcdf13a989f

// In each case, use the name exactly as it appears in the library.
// Windows Media Player does not include file extensions or file paths
// in the name. Internet URLs include the entire path, but not the 
// file 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));

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)

See Also

Previous Next