IWMPControls::currentItem 屬性

[與此頁面相關聯的功能Windows 媒體播放機 SDK是舊版功能。 它已被 MediaPlayer 取代MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用MediaPlayer,而不是Windows 媒體播放機 SDK。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]

currentItem屬性會取得或設定播放清單中的目前媒體專案。

Syntax

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