Share via


Windows Media Player 11 SDK IWMPMediaCollection.getAll (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPMediaCollection.getAll (VB and C#)

The getAll method returns an IWMPPlaylist interface that corresponds to the playlist that contains all media items in the library.

  

Parameters

This method takes 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.

Example Code

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. 
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()

FakePre-49b78e2fa00c486ba2ef6d7bd117867e-fb286c9829cb4637ba7ec7ce6c79a2e6

// 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();

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)

See Also

Previous Next