/// <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"); }
private void Player_MediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) { try { IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2; IWMPErrorItem errorItem = errSource.Error; MessageBox.Show("Error " + errorItem.errorCode.ToString("X") + " in " + errSource.sourceURL); } catch (InvalidCastException) { MessageBox.Show("Error."); } }
/// <summary> /// Handler for any execptions thrown by the MediaPlayer object. /// Displays these errors to user in a MessageBox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mediaPlayer_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."); } }
internal void RaiseOnMediaError(object sender, _WMPOCXEvents_MediaErrorEvent e) { if ((this.MediaError != null)) { this.MediaError(sender, e); } }
public virtual void MediaError(object pMediaObject) { _WMPOCXEvents_MediaErrorEvent mediaerrorEvent = new _WMPOCXEvents_MediaErrorEvent(pMediaObject); this.parent.RaiseOnMediaError(this.parent, mediaerrorEvent); }