Source Property (MediaElement)

Gets or sets a media source on the MediaElement.

XAML
<object Source="string" .../>
Scripting
value = object.Source
object.Source = value

Property Value

string

A string that specifies the source of the element.

This property is read/write. The default value is null.

Remarks

Setting the Source will reset the media's Position to 00:00:00.

The string provided for the Source property is interpreted as a Uniform Resource Identifier (URI). This is in contrast to an Internationalized Resource Identifier (IRI). This distinction means that characters used to identify a Source that are outside of US-ASCII will need to be encoded.

Relative references are permitted. The starting location for the relative reference is the HTML page that contains the current Silverlight plug-in.

Cross-domain URIs are permitted (using http). You can also use the monikers mms:, rtsp:, or rtspt: in your URI to point to a media source. In each case the actual protocol and URI scheme falls back to http (with possible further fallbacks in behavior for differentiating streaming from progressive downloads), but the value of Source will retain your moniker.

If you are not accessing cross-domain sources or live streaming media, you should consider using the SetSource method instead of setting Source directly. This method provides the advantage of letting you track the download. Also, you can download content as a package and access parts from within the package.

In JavaScript, you can set the runtime value to null or an empty string to cause the media to unload and no longer render. Doing so does not fire an MediaFailed event. In contrast, setting Source to a URI value that does not resolve will fire a MediaFailed event. Also, a SetValue error is thrown.

You can specify an initial XAML value of "" (empty string) and then set the value in script at a later time, to create a nonplaying placeholder.

The MediaFailed event can occur if the initial Source attribute value in XAML does not specify a valid source.

Setting a cross-domain URI for Source will either succeed or will not return a valid status for any failure. In this case, a MediaFailed event does not occur. Instead, an error is thrown on the SetValue method call for setting "Source."

Backslashes (\) in Source URIs are not permitted; always use forward slashes (/).

Applies To

MediaElement

See Also

Media Overview
Supported Media Formats and ProtocolsMediaFailed