IWMPMediaCollection::getByAlbum 方法

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

getByAlbum 方法返回一个 IWMPPlaylist 接口,该接口提供对指定相册中的媒体项的访问权限。

语法

public IWMPPlaylist getByAlbum(
  System.String bstrAlbum
);

Public Function getByAlbum( _
  ByVal bstrAlbum As System.String _
) As IWMPPlaylist
Implements IWMPMediaCollection.getByAlbum

parameters

bstrAlbum [in]

作为相册标题的 System.String

返回值

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

注解

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

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

示例

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

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

    // Create the playlist using getByAlbum. 
    WMPLib.IWMPPlaylist pl = player.mediaCollection.getByAlbum(album);

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

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

Public Sub playAlbum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles playAlbum.Click

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

    ' Retrieve the album title text that the user entered in the text box. 
    Dim album As String = getAlbum.Text

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

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