MediaCollection.getAll 方法

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

getAll 方法检索包含库中所有媒体项的播放列表。

语法

retVal = MediaCollection.getAll()

参数

此方法没有任何参数。

返回值

此方法返回 一个 Playlist 对象。

备注

若要使用此方法,需要对库的读取访问权限。 有关详细信息,请参阅 库访问

示例

以下 JScript 示例使用 MediaCollectiongetAll 可从媒体集合中随机播放媒体项。 创建 ID 为“Player”的 Player 对象。

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

// Generate a random number using the media count.
var rand = Math.random() * count;

// Round down the random number to the nearest integer.
rand = Math.floor(rand);

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

// Play the media item.
// Player.controls.play();

要求

要求
版本
Windows 媒体播放器版本 7.0 或更高版本。
DLL
Wmp.dll

另请参阅

MediaCollection 对象

Playlist 对象

Settings.mediaAccessRights

Settings.requestMediaAccessRights