IWMPControls::currentItem 属性

[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]

currentItem 属性获取或设置播放列表中的当前媒体项。

语法

public IWMPMedia currentItem {get; set;}

Public Property currentItem As IWMPMedia

属性值

表示媒体项的 WMPLib.IWMPMedia 接口。

备注

此属性仅适用于当前播放列表中的项目。 不支持将 currentItem 设置为已保存媒体项的接口。

示例

以下示例使用 currentItem 将玩家的当前媒体项设置为从列表框中选择的项。 列表框已填充当前播放列表中的所有项。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 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

要求

要求
版本
Windows 媒体播放器 9 系列或更高版本
命名空间
WMPLib
程序集
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另请参阅

IWMPControlsInterface (VB 和 C#)

IWMPMediaInterface (VB 和 C#)

IWMPPlaylistCollection.getByName (VB 和 C#)