次の方法で共有


IWMPControls::currentItem property

[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 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

Requirement Value
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#)