AxWindowsMediaPlayer 物件的 CurrentPlaylistChange 事件

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

CurrentPlaylistChange 事件發生于目前播放清單內的某個專案變更時。

[C#]
private void player_CurrentPlaylistChange(
  object sender,
  _WMPOCXEvents_CurrentPlaylistChangeEvent e
)

[Visual Basic]
Private Sub player_CurrentPlaylistChange(
  sender As Object,
  e As _WMPOCXEvents_CurrentPlaylistChangeEvent
) Handles player.CurrentPlaylistChange

事件資料

與此事件相關聯的處理常式類型為 AxWMPLib._WMPOCXEvents_CurrentPlaylistChangeEventHandler。 此處理程式會收到類型 為 AxWMPLib._WMPOCXEvents_CurrentPlaylistChangeEvent的引數,其中包含與這個事件相關的下列屬性。

屬性 描述
變更 WMPLib.WMPPlaylistChangeEventTypeAn 列舉值,指出播放清單發生變更的類型。

備註

當不同的播放清單變成目前的播放清單時,不會發生此事件。 只有在目前播放清單內發生變更時,才會發生此情況,例如將媒體專案附加至播放清單。

範例

下列範例會顯示目前播放清單中所有媒體專案的名稱,以回應 CurrentPlaylistChange 事件。 AxWMPLib.AxWindowsMediaPlayer 物件是由名為 player 的變數表示。

// Add a delegate for the CurrentPlaylistChange event.
player.CurrentPlaylistChange += new AxWMPLib._WMPOCXEvents_CurrentPlaylistChangeEventHandler(player_CurrentPlaylistChange);  


private void player_CurrentPlaylistChange(object sender, AxWMPLib._WMPOCXEvents_CurrentPlaylistChangeEvent e)
{
    switch(e.change)
    {
        // Only update the list for the move, delete, insert, and append event types.
        case WMPLib.WMPPlaylistChangeEventType.wmplcMove:    // Value = 3
        case WMPLib.WMPPlaylistChangeEventType.wmplcDelete:  // Value = 4
        case WMPLib.WMPPlaylistChangeEventType.wmplcInsert:  // Value = 5
        case WMPLib.WMPPlaylistChangeEventType.wmplcAppend:  // Value = 6

        // Create a string array large enough to hold all of the media item names.
        int count = player.currentPlaylist.count;
        string[] mediaItems = new string[count];

        // Clear any previous contents of the text box.
        playlistItems.Clear();

        // Loop through the playlist and store each media item name.
        for (int i = 0; i < count; i++)
        {
            mediaItems[i] = player.currentPlaylist.get_Item(i).name;
        }

        // Display the media item names.
        playlistItems.Lines = mediaItems;
        break;
      
        default:
            break;
    }
}

Public Sub player_CurrentPlaylistChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_CurrentPlaylistChangeEvent) Handles player.CurrentPlaylistChange

    Select Case e.change

        &#39; Only update the list for the move, delete, insert, and append event types.
        Case WMPLib.WMPPlaylistChangeEventType.wmplcMove   &#39; Value = 3
        Case WMPLib.WMPPlaylistChangeEventType.wmplcDelete &#39; Value = 4
        Case WMPLib.WMPPlaylistChangeEventType.wmplcInsert &#39; Value = 5
        Case WMPLib.WMPPlaylistChangeEventType.wmplcAppend &#39; Value = 6

            &#39; Create a string array large enough to hold all of the media item names.
            Dim count As Integer = player.currentPlaylist.count
            Dim mediaItems(count) As String

            &#39; Clear any previous contents of the text box.
            playlistItems.Clear()

            &#39; Loop through the playlist and store each media item name.
            For i As Integer = 0 To (count - 1)

                mediaItems(i) = player.currentPlaylist.Item(i).name

            Next i

            &#39; Display the media item names.
            playlistItems.Lines = mediaItems
    End Select

End Sub

規格需求

需求
版本
Windows 媒體播放機 9 系列或更新版本
命名空間
AxWMPLib
組件
AxInterop.WMPLib.dll (AxInterop.WMPLib.dll.dll)

另請參閱

AxWindowsMediaPlayer 物件 (VB 和 C#)

AxWindowsMediaPlayer.currentPlaylist (VB 和 C#)

AxWindowsMediaPlayer.PlaylistChange 事件 (VB 和 C#)

WMPPlaylistChangeEventType