Freigeben über


Troubleshooting the Silverlight MediaElement 4001 Error

This is my first post on Silverlight, so I thought I would post on a common issue that I've seen developers have problems with. Since I focus mainly on the MediaElement piece of Silverlight I'm going to stick almost solely to that on this blog when I post about Silverlight.

If you've ever developed a Silverlight application that plays video, you've probably at some point seen the following error:

Silverlight error message
ErrorCode: 4001
ErrorType: MediaError
Message: AG_E_NETWORK_ERROR

In fact, it's probably the only error you've ever seen with regards to the MediaElement. That's because it IS the only error that MediaElement throws.

Here are a few possible causes for this error:

  • Streaming from WMS through an Authenticated Proxy - Silverlight gets video in two different modes. If the video is coming from a web server, such as IIS, then it is progressively downloading the video from the web site. This downloading is handled by the browser. If Silverlight is streaming from a Windows Media server then this streaming is handled internally by Silverlight and not by the browser. Since browsers support proxy authentication you will not see the 4001 error if you are getting the video content from a web server. Silverlight does not support proxy authentication natively and therefore doesn't support proxy authentication when streaming from a Windows Media server.

    There are only two workarounds, and they are the obvious ones. First, don't require proxy authentication on the proxy. Second, put the content on a web server. In the enterprise, this may not be an option.

     

  • Codec Not Supported by Silverlight - Because Silverlight streams .wmv and .wma files you may have a video encoded with a codec that Silverlight does not support. The file extension .wma and .wmv are both forms of the ASF file format that Silverlight supports. However, because ASF is just a file container you can use just about any codec to compress the audio and video within that ASF container. While the Windows Media Audio v9 codec (often abbreviated WMA) and Windows Media Video v9 codec (often abbreviated WMV) are some of the most common codecs you do occasionally find other codecs within .wma and .wmv files. For example, a number of years ago Windows Media Encoder used the ACELP.net audio codec for voice. Silverlight does not support this codec, so you get an error.

    The workaround for this is to re-encode the video into a format that Silverlight supports. For a list of supported codecs, see the MSDN article: Supported Media Formats, Protocols, and Log Fields.

  • Incorrect Pathing - This is your common 'file not found' type problem. If you mistype the path to the video then you're going to get the 4001 error. You can often find pathing issues by typing the full URL into your browser. If Windows Media Player opens and cannot find the file then most likely you are using an incorrect URL. If you are a developer and are building a Silverlight 2 project with Visual Studio and including the video as part of your project, make sure that the video is in the ClientBin folder in the Web project.

  • Crossing Zones - As part of the Silverlight security model, when you run an application in a more secure zone (such as from the local hard drive) you cannot play video from a less secure zone. An example of this is building a Silverlight application that is run from the local web server that Visual Studio instantiates. In this scenario you are crossing from the Local Intranet Zone where the Silverlight application is running to the Internet Zone where the video is being streamed from. This is not allowed for security reasons.

    As a workaround try to keep both the location were the Silverlight application and the video are in the same zone. Keep in mind that it IS possible to cross domains, just not zones. You could host your Silverlight application on one domain and serve your video content from another domain.