MediaCollection.getAll 方法

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

getAll方法會擷取包含媒體櫃中所有媒體專案的播放清單。

語法

retVal = MediaCollection.getAll()

參數

這個方法沒有任何參數。

傳回值

這個方法會傳回 Playlist 物件。

備註

若要使用此方法,需要程式庫的讀取權限。 如需詳細資訊,請參閱 程式庫存取

範例

下列 JScript 範例使用 MediaCollectiongetAll 可從媒體集合隨機播放媒體專案。 Player物件是以 ID = 「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