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
' 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.
Dim count As Integer = player.currentPlaylist.count
Dim mediaItems(count) As String
' Clear any previous contents of the text box.
playlistItems.Clear()
' 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
' Display the media item names.
playlistItems.Lines = mediaItems
End Select
End Sub
規格需求
需求 | 值 |
---|---|
版本 |
Windows 媒體播放機 9 系列或更新版本 |
命名空間 |
AxWMPLib |
組件 |
|
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應