Gets or sets the current position of progress through the media's playback time.
Syntax
Property value
Type: System.TimeSpan [.NET] | Windows::Foundation::TimeSpan [C++]
The amount of time since the beginning of the media. The default is a TimeSpan with value "0:0:0".
Remarks
Set this property to set a specific start-play position within the media.
If you are not sure of the current media source loaded as MediaElement.Source, always check CanSeek first. A streaming media source results in the MediaElement reporting CanSeek as false, and in this case you cannot use Position to set the playback point.
If Position is settable, then these value constraints apply:
- If Position is set to a negative value, the value will revert to a TimeSpan with value "0:0:0".
- If Position is set to a value larger than the media's NaturalDuration, then Position becomes the value of NaturalDuration.
Notes on XAML syntax
Setting a Position value in XAML is technically possible but not common. If you do set a Position in XAML, you should simulate the "FromString" type conversion behavior for a TimeSpan, in other words specify the value in the form "H:MM:SS" with an optional decimal value for milliseconds.
Examples
This code shows the simple pattern of setting Position based on detecting the changed NewValue of a Slider control. The Slider control is part of the MediaElement transport UI, and enables the user to set the Position. In this code, "sliderpressed" is a sentinel Boolean value that is set to true while a pointer is pressed, so that the code does not change the position during intermediate slider repositioning. A prerequisite (not shown) is that the Maximum of the Slider should be reset to be the current media source's NaturalDuration whenever a new non-streaming media source is finished loading. For the context of the larger code sample where this snippet came from, see Quickstart: Creating a media player app.
void timelineSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { if (!_sliderpressed) { videoMediaElement.Position = TimeSpan.FromSeconds(e.NewValue); } }
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 3/12/2013