Partager via


IWMPMediaCollection::remove 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 remove method removes a specified item from the media collection.

Syntax

public void remove(
  IWMPMedia pItem,
  System.Boolean varfDeleteFile
);

Public Sub remove( _
  ByVal pItem As IWMPMedia, _
  ByVal varfDeleteFile As System.Boolean _
)
Implements IWMPMediaCollection.remove

Parameters

pItem [in]

A WMPLib.IWMPMedia interface that identifies the item to remove.

varfDeleteFile [in]

A System.Boolean value that specifies whether the method should remove the specified item from the library.

Return value

This method does not return a value.

Remarks

This method deletes an item from the library. This method does not delete files from the user's computer.

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

Examples

The following example, after prompting the user, permanently deletes the first media item in the media collection by using remove. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

// Get an interface to the first item from the media collection. 
WMPLib.IWMPMedia3 media = (WMPLib.IWMPMedia3)player.mediaCollection.getAll().get_Item(0);

// Store the name of the retrieved media item.
string mediaName = media.name;

// Prepare a message, a caption and buttons for the user prompt.
string message = ("OK to permanently delete " + mediaName + "?");
string caption = "Confirm deletion";
System.Windows.Forms.MessageBoxButtons buttons = System.Windows.Forms.MessageBoxButtons.OKCancel;

// Prompt the user for permission to delete the object.
System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(message, caption, buttons);

// Check the user response.
if (result == System.Windows.Forms.DialogResult.OK)
{
    // Permanently delete the item.
    player.mediaCollection.remove(media, true);

    // Report that the item was deleted.
    System.Windows.Forms.MessageBox.Show("Deleted item " + mediaName);
}

' Get an interface to the first item from the media collection. 
Dim media As WMPLib.IWMPMedia3 = player.mediaCollection.getAll().Item(0)

' Store the name of the retrieved media item.
Dim mediaName As String = media.name

' Prepare a message, a caption and buttons for the user prompt.
Dim message As String = ("OK to permanently delete " + mediaName + "?")
Dim caption As String = "Confirm deletion"
Dim buttons As System.Windows.Forms.MessageBoxButtons = System.Windows.Forms.MessageBoxButtons.OKCancel

' Prompt the user for permission to delete the object.
Dim result As System.Windows.Forms.DialogResult = System.Windows.Forms.MessageBox.Show(message, caption, buttons)

' Check the user response.
If (result = System.Windows.Forms.DialogResult.OK) Then

    ' Permanently delete the item.
    player.mediaCollection.remove(media, True)

    ' Report that the item was deleted.
    System.Windows.Forms.MessageBox.Show("Deleted item " + mediaName)

End If

Requirements

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

See also

IWMPMedia Interface (VB and C#)

IWMPMediaCollection Interface (VB and C#)

IWMPMediaCollection.add (VB and C#)