IWMPPlaylist.Item (VB 和 C#)

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

C# (get_Item 方法的 Item 属性) 获取指向指定索引处的媒体项的接口。

[Visual Basic]
ReadOnly Property Item(
  lIndex As System.Int32
) As IWMPMedia
[C#]
IWMPMedia get_Item (
  System.Int32 lIndex 
);

parameters

lIndex

一个 System.Int32 ,它是播放列表中媒体项的索引。

属性值

一个 WMPLib.IWMPMedia 接口,用于提供对指定索引处的媒体项的访问权限。

备注

IWMPPlaylist.Item 是 Visual Basic 中采用参数的只读属性,而在 C# 中,它称为 IWMPPlaylist.get_Item 方法。

示例

以下示例使用 C#) 中的 get_Item 方法 (Item 属性,根据用户选择从播放列表中检索媒体项。 已创建一个列表框,其中包含名为“audioPlaylist”的播放列表中的标题。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

private void weblist_SelectedIndexChanged(object sender, System.EventArgs e)
{
    // Store the index of the selected item in the list box.
    int index = ((System.Windows.Forms.ListBox)sender).SelectedIndex;

    // Store the corresponding media item from the playlist.
    WMPLib.IWMPMedia listItem = audioPlaylist.get_Item(index);

    // Set the player URL to the URL of the selected media item.
    player.URL = listItem.sourceURL;
}

Public Sub weblist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles weblist.SelectedIndexChanged

    ' Store the index of the selected item in the list box.
    Dim lb As System.Windows.Forms.ListBox = sender
    Dim index As Integer = lb.SelectedIndex

    ' Store the corresponding media item from the playlist.
    Dim listItem As WMPLib.IWMPMedia = audioPlaylist.Item(index)

    ' Set the player URL to the URL of the selected media item.
    player.URL = listItem.sourceURL

End Sub

要求

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

另请参阅

IWMPMedia 接口 (VB 和 C#)

IWMPPlaylist 接口 (VB 和 C#)

IWMPPlaylist.insertItem (VB 和 C#)

IWMPPlaylist.removeItem (VB 和 C#)

IWMPSettings2.mediaAccessRights (VB 和 C#)

IWMPSettings2.requestMediaAccessRights (VB 和 C#)