IWMPPlaylist.Item (VB and C#)

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The Item property (the get_Item method in C#) gets an interface to the media item at the specified index.

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

Parameters

lIndex

A System.Int32 that is the index of the media item in the playlist.

Property Value

An WMPLib.IWMPMedia interface that provides access to the media item at the specified index.

Remarks

IWMPPlaylist.Item is a read-only property in Visual Basic that takes a parameter, while in C# it is referred to as the IWMPPlaylist.get_Item method.

Examples

The following example uses the Item property (the get_Item method in C#) to retrieve a media item from a playlist based on a user selection. A list box was created with the name weblist, and filled with the titles from the playlist called audioPlaylist. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named 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

Requirements

Requirement Value
Version
Windows Media Player 9 Series or later
Namespace
WMPLib
Assembly
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

See also

IWMPMedia Interface (VB and C#)

IWMPPlaylist Interface (VB and C#)

IWMPPlaylist.insertItem (VB and C#)

IWMPPlaylist.removeItem (VB and C#)

IWMPSettings2.mediaAccessRights (VB and C#)

IWMPSettings2.requestMediaAccessRights (VB and C#)