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 |
程序集 |
|
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈