Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MediaElement.MediaFailed event

Applies to Windows and Windows Phone

Occurs when there is an error associated with the media Source.

Syntax


public event ExceptionRoutedEventHandler MediaFailed


<MediaElement MediaFailed="eventhandler" .../>

Event information

Delegate ExceptionRoutedEventHandler

Remarks

It is a best practice to always handle the MediaFailed event and take appropriate action.

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;
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

MediaElement

 

 

Show:
© 2014 Microsoft. All rights reserved.