다음을 통해 공유


IWMPControls::playItem method

[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 playItem method plays the specified media item.

Syntax

public void playItem(
  IWMPMedia pIWMPMedia
);

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

Parameters

pIWMPMedia [in]

A WMPLib.IWMPMedia interface to the media item.

Return value

This method does not return a value.

Remarks

The media item will load and play automatically, regardless of the value of the IWMPSettings.autoStart property. To load an item without playing it automatically, set IWMPSettings.autoStart to false and assign a value to AxWindowsMediaPlayer.URL, after which IWMPControls.play can be called to start playing the item.

Note

playItem works only with items in AxWindowsMediaPlayer.currentPlaylist. Calling playItem with a reference to a saved media item is not supported.

Examples

The following example uses playItem to play a media item from the current playlist. The item to play is chosen based upon its position in the playlist. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named 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)

Requirements

Requirement Value
Version
Windows Media Player 9 Series or later
Namespace
WMPLib
Assembly
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

See also

AxWindowsMediaPlayer.currentPlaylist (VB and C#)

AxWindowsMediaPlayer.URL (VB and C#)

IWMPControls Interface (VB and C#)

IWMPControls.play (VB and C#)

IWMPPlaylist.Item (VB and C#)

IWMPSettings.autoStart (VB and C#)