private void wmp_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) { try // If the Player encounters a corrupt or missing file, // show the hexadecimal error code and URL. { IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2; IWMPErrorItem errorItem = errSource.Error; MessageBox.Show("Error " + errorItem.errorCode.ToString("X") + " in " + errSource.sourceURL); } catch (InvalidCastException) // In case pMediaObject is not an IWMPMedia item. { MessageBox.Show("Error."); } }
/// <summary> /// Generic handler for Player error events. /// </summary> /// <remarks> /// Information returned in the event arguments is limited to the media object /// that was the source of the error. Further information can be obtained from /// IWMPMedia2.Error. Use IWMErrorItem.Description with caution, because messages /// may be more relevant to the Windows Media Player than to your application. /// </remarks> private void Player_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) { IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2; IWMPErrorItem errorItem = errSource.Error; String errorDesc = errorItem.errorDescription; String errorStr = "Error " + errorItem.errorCode.ToString("X") + " in " + errSource.sourceURL + "\n" + errorDesc; MessageBox.Show(errorStr, "Player Error"); }
// MediaErrorHandler(sender, e) is dispatched when a media error occurs; i.e.: IO error. private void MediaErrorHandler(object sender, AxWMPLib._WMPOCXEvents_MediaErrorEvent e) { Console.WriteLine("Media error occurred."); _player.close(); }
private void wmPlayer_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) { try // If the Player encounters a corrupt or missing ioItem, // show the hexadecimal error code and URL. { var errSource = e.pMediaObject as WMPLib.IWMPMedia2; if (errSource != null) { WMPLib.IWMPErrorItem errorItem = errSource.Error; Logger.Error("Error " + errorItem.errorCode.ToString("X") + " in " + errSource.sourceURL); AnalyticsHelper.FireEvent("WMP Error - " + errorItem.errorCode.ToString("X")); AnalyticsHelper.FireEvent("WMP Error - " + errorItem.errorCode.ToString("X") + " - " + Path.GetExtension(errSource.sourceURL)); try { FileInfo fileInfo = new FileInfo(errSource.sourceURL); UploadMediaInfo(fileInfo, errorItem.errorCode.ToString("X")); } catch (Exception ex) { Logger.Error("Error creating FileInfo for " + errSource.sourceURL + ": " + ex); } if (PlayerError != null) { var playerErrorEventArgs = new PlayerErrorEventArgs(); if (errorItem.errorCode.ToString("X") == "C00D1199") { playerErrorEventArgs.ErrorMessage = "Ah bummer! We had trouble playing your video. This is most likely due to a missing codec." + Environment.NewLine + Environment.NewLine + "The easiest fix is to download the free K-Lite Codec pack. Would you like to do that now?"; playerErrorEventArgs.SupportID = "WMPErrorC00D1199"; } else { playerErrorEventArgs.ErrorMessage = "Error loading video! Please make sure you can play this video in Windows Media Player." + Environment.NewLine + Environment.NewLine + "Error code: " + errorItem.errorCode.ToString("X") + Environment.NewLine + Environment.NewLine + "Would you like to open a support ticket?"; playerErrorEventArgs.SupportID = "ErrorLoadingVideo"; } PlayerError(sender, playerErrorEventArgs); } } else Logger.Error("Unknown error!"); } catch (InvalidCastException ex) // In case pMediaObject is not an IWMPMedia item. { Logger.Error("Exception thrown: " + ex); } }