IWMPMediaCollection::getAll 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 getAll method returns an IWMPPlaylist interface that corresponds to the playlist that contains all media items in the library.

Syntax

public IWMPPlaylist getAll();

Public Function getAll() As IWMPPlaylist
Implements IWMPMediaCollection.getAll

Parameters

This method has no parameters.

Return value

The WMPLib.IWMPPlaylist interface for the playlist that contains all of the requested media items.

Remarks

Before calling this method, you must have read access to the library. For more information, see Library Access.

There are two ways you ways you can retrieve an IWMPMediaCollection interface, and the behavior of the getAll method depends on which of those two ways you use. If you retrieve the interface by calling AxWindowsMediaPlayer.mediaCollection, then the getAll method returns all the media items in the library. However, if you retrieve the interface by calling IWMPLibrary.mediaCollection, then the getAll method returns only the audio items in the library.

Examples

The following example uses getAll to play media items randomly from the media collection. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named 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()

Requirements

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

See also

IWMPMediaCollection Interface (VB and C#)

IWMPPlaylist Interface (VB and C#)