IWMPControls::currentItem property

The currentItem property gets or sets the current media item in a playlist.

Syntax

public IWMPMedia currentItem {get; set;}

Public Property currentItem As IWMPMedia

Property value

A WMPLib.IWMPMedia interface that represents the media item.

Remarks

This property works only with items in the current playlist. Setting currentItem to the interface of a saved media item is not supported.

Examples

The following example uses currentItem to set the player's current media item to an item selected from a list box. The list box has been filled with all of the items in the current playlist. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

private void playItem_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
    int selectedItem = ((System.Windows.Forms.ListBox)sender).SelectedIndex;

    // Ensure that the previous media item is stopped.
    player.Ctlcontrols.stop();

    // Set the current item to the item selected from the list box.
    player.Ctlcontrols.currentItem = player.currentPlaylist.get_Item(selectedItem);
    
    // Play the current item.
    player.Ctlcontrols.play();
}

Public Sub playItem_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles playItem.SelectedIndexChanged

    Dim lb As System.Windows.Forms.ListBox = sender
    Dim selectedItem As Integer = lb.SelectedIndex

    ' Ensure that the previous media item is stopped.
    player.Ctlcontrols.stop()

    ' Set the current item to the item selected from the list box.
    player.Ctlcontrols.currentItem = player.currentPlaylist.Item(selectedItem)

    ' Play the current item.
    player.Ctlcontrols.play()

End Sub

Requirements

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

See also

IWMPControlsInterface (VB and C#)

IWMPMediaInterface (VB and C#)

IWMPPlaylistCollection.getByName(VB and C#)