AxWindowsMediaPlayer 对象的错误事件

[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]

当Windows 媒体播放器控件具有错误条件时,会发生 Error 事件。

[C#]
private void player_ErrorEvent(
  object sender,
  System.EventArgs e
)

[Visual Basic]
Private Sub player_ErrorEvent(  
  sender As Object,  
  e As System.EventArgs
) Handles player.ErrorEvent

事件数据

此事件不包含数据。

示例

以下示例为 Error 事件创建事件处理程序,以显示错误队列中第一个错误的说明文本。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

// Add a delegate for the Error event.
player.ErrorEvent += new EventHandler(player_ErrorEvent);

private void player_ErrorEvent(object sender, System.EventArgs e)
{
    // Get the description of the first error. 
    string errDesc = player.Error.get_Item(0).errorDescription;

    // Display the error description.
    System.Windows.Forms.MessageBox.Show(errDesc);
}

Public Sub player_ErrorEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles player.ErrorEvent

    ' Get the description of the first error. 
    Dim errDesc As String = player.Error.Item(0).errorDescription

    ' Display the error description.
    System.Windows.Forms.MessageBox.Show(errDesc)

End Sub

要求

要求
版本
Windows 媒体播放器 9 系列或更高版本
命名空间
AxWMPLib
程序集
AxInterop.WMPLib.dll (AxInterop.WMPLib.dll.dll)

另请参阅

AxWindowsMediaPlayer 对象 (VB 和 C#)

IWMPError.Item (VB 和 C#)

IWMPErrorItem.errorDescription (VB 和 C#)