Share via


Windows Media Player 11 SDK IWMPPlaylist.Item (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPPlaylist.Item (VB and C#)

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

  

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.

Example Code

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.

  
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

FakePre-626cd8b0ea6342fe9c0e109ff6a555d8-43ac220ee145474090af2d719bcf259f

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;
}

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)

See Also

Previous Next