IWMPMediaCollection::getByAttribute 方法

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

getByAttribute 方法返回一个 IWMPPlaylist 接口,该接口对应于具有指定值的指定属性。

语法

public IWMPPlaylist getByAttribute(
  System.String bstrAttribute,
  System.String bstrValue
);

Public Function getByAttribute( _
  ByVal bstrAttribute As System.String, _
  ByVal bstrValue As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByAttribute

parameters

bstrAttribute [in]

作为指定属性的 System.String

bstrValue [in]

作为指定值的 System.String

返回值

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

注解

此方法可用于为与库中属性的值匹配的媒体项创建泛型查询。 这在用户定义属性的情况下很有用。 如果该属性不存在,则会导致错误。

可以使用此方法检索特定类型的所有媒体项。 使用属性名称 MediaType 和以下值之一。

说明
音频 音乐和其他仅限音频的项目
其他 其他项,例如 .asf 文件或流的 URL。
照片 照片项目。 需要 Windows 媒体播放器 10。
播放列表 表示为媒体项的播放列表。
radio 无线电台项目。 Windows 媒体播放器 10 不使用。
视频 视频项。

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

有关 Windows 媒体播放器 支持的属性的信息,请参阅属性参考

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

示例

下面的代码示例使用 getByAttribute 播放由名为 Triode 48 的艺术家从库中的所有内容。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

// Get an interface to a playlist that contains media items by a particular artist.
WMPLib.IWMPPlaylist pl = player.mediaCollection.getByAttribute("Artist", "Triode 48");

// Make the new playlist the current one.
player.currentPlaylist = pl;

// Play the media items in the current playlist. 
player.Ctlcontrols.play();

' Get an interface to a playlist that contains media items by a particular artist.
Dim pl As WMPLib.IWMPPlaylist = player.mediaCollection.getByAttribute("Artist", "Triode 48")

' Make the new playlist the current one.
player.currentPlaylist = pl

' Play the media items in the current playlist. 
player.Ctlcontrols.play()

要求

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

另请参阅

IWMPMediaCollection 接口 (VB 和 C#)

IWMPPlaylist 接口 (VB 和 C#)

IWMPPlaylistCollection.getAll (VB 和 C#)