共用方式為


Source (MediaElement)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a media source on a MediaElement object.

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

Property Value

Type: string

A string that specifies the source of the element, as a Uniform Resource Identifier (URI).

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

Managed Equivalent

Source

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 URI instead of an Internationalized Resource Identifier (IRI). This distinction means that characters used to identify a Source that are outside the US-ASCII character set will have to be encoded.

Relative references are permitted. Using the JavaScript API and a source that loads a XAML page, 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 additional fallbacks in behavior for differentiating streaming downloads from progressive downloads), but the value of Source will retain your moniker regardless of the run-time resolution of the URI.

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 enables you to track the download. Also, you can download content as a package and access parts from within the package.

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

You can specify an initial Source value of "" (empty string) in your XAML MediaElement object element, and then set the value in script at a later time. This creates a non-playing placeholder MediaElement for which you can set Source later, in script.

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 (\) are not permitted in Source URIs; always use forward slashes (/).

Applies To

MediaElement

See Also

Reference