WPF Mediaelement.position Properties

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.