Position Property Definition: Gets or sets the current progress position of the media playback time.
// //Summary://Gets or sets the current position of the progress through media playback. // //return Result://Since the media. The default value is 00:00:00. // //Exception://T:System.InvalidOperationException://The System.Windows.Controls.MediaElement.Clock property is not null. PublicTimeSpan Position {Get;Set; }
You can see from the definition that position is not a dependency property, that you cannot use bidirectional or page bindings, and so on.
More information:
Dependency Property identifier field: Positionproperty
Use this property to be set to a specific location within the media. mediaelement.seek method. " This property is configurable and does not use a specific mediaelement.seek method.
Setting this property will have no effect on media playback if the media does not support find operations (this is the case with live streaming media). Please check the value of CanSeek before attempting to set Position.
If Position is configurable, the following run-time-value constraints apply:
-
position is set to a negative value, the value would revert to a position is set to a negative value, it reverts to 0:0:0 with a value of TimeSpan.
If you set Position to a value that is larger than the naturalduration of the media, Naturalduration is set to Position
The XAML usage of this property is not demonstrated.This value should generally not be set in XAML, because it is not guaranteed that the media can be located before it is loaded (it may be streaming media and therefore cannot be located).In the triggerAfter MediaOpened, checkThe value of the CanSeek.If the value istrue, you can locate the media, and then you can set the Position in code. However, XAML usage is technically possible, and you can use attribute strings to [days.] Hours:minutes:seconds[.fractionalseconds] format to set this usage. For further guidance on XAML syntax for time spans, see bufferingtime; The same method will be used to analyze Position.
Need to customize the timer or thread to modify or display the location of the position
Background Key code:
DispatcherTimer timer =NULL;Private voidMediaelement_mediaopened (Objectsender, RoutedEventArgs e) {Sliderposition.maximum=MediaElement.NaturalDuration.TimeSpan.TotalSeconds; //media file opened successfullyTimer =NewDispatcherTimer (); Timer. Interval= Timespan.fromseconds (1); Timer. Tick+=NewEventHandler (Timer_tick); Timer. Start ();}Private voidTimer_tick (Objectsender, EventArgs e) {Sliderposition.value=mediaElement.Position.TotalSeconds;}
WPF Mediaelement.position Properties