Share via


Windows Media Player 11 SDK IWMPControls.currentItem (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPControls.currentItem (VB and C#)

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

  

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.

Example Code

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.

  
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

FakePre-bf84637bca08469a8ce1af8a7e3fad44-7db32171e2644e959f4f326cbc745681

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

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

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

See Also

Previous Next