/// <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"); }
/// <summary> /// event handler to display any errors encountered by the player /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Player_MediaError(object sender, AxWMPLib._WMPOCXEvents_MediaErrorEvent e) { //if media error is called, check and notify user if file is missing or corrupt try { IWMPMedia2 errSource = e.pMediaObject as IWMPMedia2; IWMPErrorItem errorItem = errSource.Error; MessageBox.Show("Error " + errorItem.errorCode.ToString("X") + " in " + errSource.sourceURL); } catch (InvalidCastException ex) { MessageBox.Show("Error received:" + ex.Message); } }
private void preview_process_WMP_MediaError(object sender, AxWMPLib._WMPOCXEvents_MediaErrorEvent e) { try { IWMPMedia2 errSrc = e.pMediaObject as IWMPMedia2; IWMPErrorItem errItem = errSrc.Error; MessageBox.Show("Error " + errItem.errorCode.ToString("X") + " in " + errSrc.sourceURL); } catch (InvalidCastException) { } }
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."); } }
private void player_MediaError(object pMediaObject) { IWMPMedia2 media = pMediaObject as IWMPMedia2; if (media == null) { OnNotificationSoundError("Unknown error."); return; } else if (media.Error != null) { OnNotificationSoundError(media.Error); } Marshal.ReleaseComObject(media); }
private void mediaPlayer_MediaError(object sender, AxWMPLib._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(errorItem.errorDescription + " - " + errSource.sourceURL); } catch (InvalidCastException) // In case pMediaObject is not an IWMPMedia item. { MessageBox.Show("Error."); } }
void axWindowsMediaPlayer1_MediaError(object sender, AxWMPLib._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", CultureInfo.CurrentCulture) + " in " + errSource.sourceURL); } catch (InvalidCastException) // In case pMediaObject is not an IWMPMedia item. { MessageBox.Show("Error."); } }
private void player_MediaChange(object item) { IWMPMedia2 media = item as IWMPMedia2; if (media == null) { OnNotificationSoundError("Unknown error."); return; } // ReSharper disable once CompareOfFloatsByEqualityOperator else if (media.Error == null && media.duration == 0.0) { OnNotificationSoundError("File does not contain an audio track."); } else if (media.Error != null) { OnNotificationSoundError(media.Error); } Marshal.ReleaseComObject(media); }