IWMPMediaCollection::getAll 方法

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

getAll 方法返回一个 IWMPPlaylist 接口,该接口对应于包含库中所有媒体项的播放列表。

语法

public IWMPPlaylist getAll();

Public Function getAll() As IWMPPlaylist
Implements IWMPMediaCollection.getAll

参数

此方法没有任何参数。

返回值

包含所有请求的媒体项的播放列表的 WMPLib.IWMPPlaylist 接口。

备注

在调用此方法之前,必须具有对库的读取访问权限。 有关详细信息,请参阅 库访问

可通过两种方法检索 IWMPMediaCollection 接口, getAll 方法的行为取决于使用这两种方法中的哪一种。 如果通过调用 AxWindowsMediaPlayer.mediaCollection 检索接口,则 getAll 方法将返回库中的所有媒体项。 但是,如果通过调用 IWMPLibrary.mediaCollection 检索接口,则 getAll 方法仅返回库中的音频项。

示例

以下示例使用 getAll 从媒体集合中随机播放媒体项。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

// Create a random number generator. 
System.Random randGenerator = new System.Random();

// Store the count of all media items in the media collection.
int count = player.mediaCollection.getAll().count;

// Get a random integer using the count as the max value.
int rand = randGenerator.Next(count);

// Make the random media item the current media item.
player.currentMedia = player.mediaCollection.getAll().get_Item(rand);

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

' Create a random number generator. 
Dim randGenerator As System.Random = New System.Random()

' Store the count of all media items in the media collection.
Dim count As Integer = player.mediaCollection.getAll().count

' Get a random integer using the count as the max value.
Dim rand As Integer = randGenerator.Next(count)

' Make the random media item the current media item.
player.currentMedia = player.mediaCollection.getAll().Item(rand)

' Play the media item.
player.Ctlcontrols.play()

要求

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

另请参阅

IWMPMediaCollection 接口 (VB 和 C#)

IWMPPlaylist 接口 (VB 和 C#)