IWMPMediaCollection::getByName 方法

[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]

方法 getByName 返回一个 IWMPPlaylist 接口,该接口提供对具有指定名称的媒体项的访问。

语法

public IWMPPlaylist getByName(
  System.String bstrName
);

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

参数

bstrName [in]

作为指定名称的 System.String

返回值

检索到的媒体项的 WMPLib.IWMPPlaylist 接口。

备注

在调用此方法之前,必须具有对库的读取访问权限。 有关详细信息,请参阅 库访问

可通过两种方式检索 IWMPMediaCollection 接口,方法的行为 getByName 取决于你使用这两种方法中的哪一种。 如果通过调用 AxWindowsMediaPlayer.mediaCollection 检索接口,则 getByName 该方法将返回库中的所有媒体项。 但是,如果通过调用 IWMPLibrary.mediaCollection 检索接口,则 getByName 该方法仅返回库中具有指定属性和值的音频项。

示例

以下示例使用 getByName 从库中检索三个项。 然后,每个项都追加到当前播放列表中。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 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))

要求

要求
版本
Windows 媒体播放器 9 系列或更高版本
命名空间
WMPLib
程序集
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另请参阅

IWMPMediaCollection 接口 (VB 和 C#)

IWMPPlaylist 接口 (VB 和 C#)