IWMPControls::p layItem 方法

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

playItem方法會播放指定的媒體專案。

語法

public void playItem(
  IWMPMedia pIWMPMedia
);

Public Sub playItem( _
  ByVal pIWMPMedia As IWMPMedia _
)
Implements IWMPControls.playItem

參數

pIWMPMedia [in]

媒體專案的 WMPLib.IWMPMedia介面。

傳回值

這個方法不會傳回值。

備註

不論 IWMPSettings.autoStart 屬性的值為何,媒體專案都會自動載入和播放。 若要載入專案而不自動播放,請將 IWMPSettings.autoStart 設定為 false ,並將值指派給 AxWindowsMediaPlayer.URL,之後可以呼叫 IWMPControls.play 開始播放專案。

注意

playItem 僅適用于 AxWindowsMediaPlayer.currentPlaylist中的專案。 不支援使用已儲存媒體專案的參考呼叫 playItem

範例

下列範例會使用 playItem 從目前的播放清單播放媒體專案。 要播放的專案會根據其在播放清單中的位置來選擇。 AxWMPLib.AxWindowsMediaPlayer物件是由名為 player 的變數表示。

// Declare a variable to hold the position of the media item 
// in the current playlist. An arbitrary value is supplied here.
int index = 3;

// Get the media item at the fourth position in the current playlist.
WMPLib.IWMPMedia media = player.currentPlaylist.get_Item(index);

// Play the media item.
player.Ctlcontrols.playItem(media);

' Declare a variable to hold the position of the media item 
' in the current playlist. An arbitrary value is supplied here.
Dim index As Integer = 3

' Get the media item at the fourth position in the current playlist.
Dim Media As WMPLib.IWMPMedia = player.currentPlaylist.Item(index)

' Play the media item.
player.Ctlcontrols.playItem(Media)

規格需求

需求
版本
Windows 媒體播放機 9 系列或更新版本
命名空間
WMPLib
組件
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另請參閱

AxWindowsMediaPlayer.currentPlaylist (VB 和 C#)

AxWindowsMediaPlayer.URL (VB 和 C#)

VB 和 C#) (IWMPControls 介面

IWMPControls.play (VB 和 C#)

IWMPPlaylist.Item (VB 和 C#)

IWMPSettings.autoStart (VB 和 C#)