IWMPMediaCollection::getByGenre 方法

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

方法 getByGenre 返回一个 IWMPPlaylist 接口,该接口提供对指定流派的媒体项的访问权限。

语法

public IWMPPlaylist getByGenre(
  System.String bstrGenre
);

Public Function getByGenre( _
  ByVal bstrGenre As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByGenre

参数

bstrGenre [in]

作为流派名称的 System.String

返回值

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

备注

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

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

示例

以下示例使用 getByGenre 在用户单击按钮时检索媒体项的播放列表。 播放列表包含在文本框中用户指定的流派的项目。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

private void playGenre_Click(object sender, System.EventArgs e)
{ 
    // ...Add code to ensure that the text box contains a valid value.
 
    // Retrieve the genre that the user entered in the text box. 
    string genre = getGenre.Text;

    // Create the playlist using getByGenre. 
    WMPLib.IWMPPlaylist pl = player.mediaCollection.getByGenre(genre);

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

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

Public Sub playGenre_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles playGenre.Click

    ' ...Add code to ensure that the text box contains a valid value.

    ' Retrieve the genre that the user entered in the text box. 
    Dim genre As String = getGenre.Text

    ' Create the playlist using getByGenre. 
    Dim pl As WMPLib.IWMPPlaylist = player.mediaCollection.getByGenre(genre)

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

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

End Sub

要求

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

另请参阅

IWMPMediaCollection 接口 (VB 和 C#)

IWMPPlaylist 接口 (VB 和 C#)