MediaElement.MediaFailed
MediaElement.MediaFailed
MediaElement.MediaFailed
MediaElement.MediaFailed
Event
Definition
public : event ExceptionRoutedEventHandler MediaFailed
// Register
event_token MediaFailed(ExceptionRoutedEventHandler const& handler) const;
// Revoke with event_token
void MediaFailed(event_token const& cookie) const;
// Revoke with event_revoker
MediaFailed_revoker MediaFailed(auto_revoke_t, ExceptionRoutedEventHandler const& handler) const;
public event ExceptionRoutedEventHandler MediaFailed
Public Event MediaFailed As ExceptionRoutedEventHandler
<MediaElement MediaFailed="eventhandler" .../>
Examples
The following code creates a MediaFailed event handler that calls a helper function to retrieve the HRESULT from the event arguments.
private void videoMediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
// get HRESULT from event args
string hr = GetHresultFromErrorMessage(e);
// Handle media failed event appropriately
}
private string GetHresultFromErrorMessage(ExceptionRoutedEventArgs e)
{
String hr = String.Empty;
String token = "HRESULT - ";
const int hrLength = 10; // eg "0xFFFFFFFF"
int tokenPos = e.ErrorMessage.IndexOf(token, StringComparison.Ordinal);
if (tokenPos != -1)
{
hr = e.ErrorMessage.Substring(tokenPos + token.Length, hrLength);
}
return hr;
}
Remarks
It is a best practice to always handle the MediaFailed event and take appropriate action.
Feedback
Loading feedback...