AxWindowsMediaPlayer 对象的 PlayStateChange 事件
[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
当Windows 媒体播放器控件的播放状态更改时,将发生 PlayStateChange 事件。
[C#]
private void player_PlayStateChange(
object sender,
_WMPOCXEvents_PlayStateChangeEvent e
)
[Visual Basic]
Private Sub player_PlayStateChange(
sender As Object,
e As _WMPOCXEvents_PlayStateChangeEvent
) Handles player.PlayStateChange
事件数据
与此事件关联的处理程序的类型为 AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler。 此处理程序接收 AxWMPLib._WMPOCXEvents_PlayStateChangeEvent 类型的参数,其中包含与此事件相关的以下属性。
属性 | 说明 |
---|---|
newState | System.Int32 指定新状态。 |
备注
Windows 媒体播放器状态不保证按任何特定顺序发生。 此外,并非每个状态都必然在一系列事件期间发生。 不应编写依赖于状态顺序的代码。
示例
以下示例演示了在标签中显示当前播放状态的 PlayStateChange 事件的事件处理程序。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。
// Add a delegate for the PlayStateChange event.
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
// Test the current state of the player and display a message for each state.
switch (e.newState)
{
case 0: // Undefined
currentStateLabel.Text = "Undefined";
break;
case 1: // Stopped
currentStateLabel.Text = "Stopped";
break;
case 2: // Paused
currentStateLabel.Text = "Paused";
break;
case 3: // Playing
currentStateLabel.Text = "Playing";
break;
case 4: // ScanForward
currentStateLabel.Text = "ScanForward";
break;
case 5: // ScanReverse
currentStateLabel.Text = "ScanReverse";
break;
case 6: // Buffering
currentStateLabel.Text = "Buffering";
break;
case 7: // Waiting
currentStateLabel.Text = "Waiting";
break;
case 8: // MediaEnded
currentStateLabel.Text = "MediaEnded";
break;
case 9: // Transitioning
currentStateLabel.Text = "Transitioning";
break;
case 10: // Ready
currentStateLabel.Text = "Ready";
break;
case 11: // Reconnecting
currentStateLabel.Text = "Reconnecting";
break;
case 12: // Last
currentStateLabel.Text = "Last";
break;
default:
currentStateLabel.Text = ("Unknown State: " + e.newState.ToString());
break;
}
}
Public Sub player_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles player.PlayStateChange
' Test the current state of the player, display a message for each state.
Select Case e.newState
Case 0 ' Undefined
currentStateLabel.Text = "Undefined"
Case 1 ' Stopped
currentStateLabel.Text = "Stopped"
Case 2 ' Paused
currentStateLabel.Text = "Paused"
Case 3 ' Playing
currentStateLabel.Text = "Playing"
Case 4 ' ScanForward
currentStateLabel.Text = "ScanForward"
Case 5 ' ScanReverse
currentStateLabel.Text = "ScanReverse"
Case 6 ' Buffering
currentStateLabel.Text = "Buffering"
Case 7 ' Waiting
currentStateLabel.Text = "Waiting"
Case 8 ' MediaEnded
currentStateLabel.Text = "MediaEnded"
Case 9 ' Transitioning
currentStateLabel.Text = "Transitioning"
Case 10 ' Ready
currentStateLabel.Text = "Ready"
Case 11 ' Reconnecting
currentStateLabel.Text = "Reconnecting"
Case 12 ' Last
currentStateLabel.Text = "Last"
Case Else
currentStateLabel.Text = ("Unknown State: " + e.newState.ToString())
End Select
End Sub
要求
要求 | 值 |
---|---|
版本 |
Windows 媒体播放器 9 系列或更高版本 |
命名空间 |
AxWMPLib |
程序集 |
|
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈