CurrentPosition Property

Summary
Gets or sets the current position, relative to the total duration of the media, in seconds.
Syntax
C#
VB
C++
public virtual double CurrentPosition { get; set; } 
Public Overridable Property CurrentPosition As Double 
public: 
virtual property double CurrentPosition { 
   double get(); 
   void set (    double ); 
} 

Property Value

A value representing the current playback position.

Remarks

This property is the current position that playback has reached. The value ignores the playback rate and start time. For example, if the rate is set to 2.0 and the start time to 5 seconds, playing the media for 4 seconds yields a current position of 9.0 seconds (5 + 4 x 2.0). If the media is paused or stopped, the current position is the point at which playback will resume. Call CheckSeekingCapabilities to determine whether PlaySeeking.Forward and PlaySeeking.Backward are enabled. For more information, refer to the PlaySeeking enumeration.

Example
C#
VB
using Leadtools; 
using Leadtools.MediaFoundation; 
using LeadtoolsMediaFoundationExamples.Fixtures; 
 
public bool _result = false; 
public PlayCtrlForm _form = new PlayCtrlForm(); 
double _duration = 0.0; 
double _currentPos = -1; 
 
public void PlayExample() 
{ 
   // reference the play control 
   PlayCtrl playctrl = _form.PlayCtrl; 
 
   // input file 
   string inFile = Path.Combine(LEAD_VARS.MediaDir, "PlayCtrl_Source.avi"); 
 
   try 
   { 
      // set autostart to false 
      playctrl.AutoStart = false; 
 
      // set the play count to 2 
      playctrl.PlayCount = 2; 
 
      // set our source media file 
      playctrl.SourceFile = inFile; 
 
      // get the reported duration 
      _duration = playctrl.Duration; 
 
      // set the playback rate to 2x 
      if (playctrl.IsRateSupported(2.0)) 
         playctrl.Rate = 2.0; 
 
      // set event handler to get tracking position changes 
      playctrl.TrackingPositionChanged += new TrackingPositionChangedEventHandler(PlayCtrl_TrackingPositionChanged); 
 
      // run it! 
      playctrl.Run(); 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
 
   // we'll loop on the state and pump messages for this example. 
   // but you should not need to if running from a Windows Forms application. 
   while (playctrl.State == PlayState.Running) 
      Application.DoEvents(); 
 
   // set the result to determine if the reported duration 
   // is the same as the final position from tracking 
   _result = (_duration == _currentPos && _duration > 0.0); 
} 
 
void PlayCtrl_TrackingPositionChanged(object sender, TrackingPositionChangedEventArgs e) 
{ 
   // get the frame and tracking positions for demonstration only 
   int frame = _form.PlayCtrl.CurrentFramePosition; 
   int tracking = _form.PlayCtrl.CurrentTrackingPosition; 
 
   // get the current position 
   _currentPos = Math.Max(_currentPos, _form.PlayCtrl.CurrentPosition); 
} 
 
static class LEAD_VARS 
{ 
   public const string MediaDir = @"C:\LEADTOOLS21\Media"; 
} 
Imports Leadtools 
Imports Leadtools.MediaFoundation 
Imports LeadtoolsMediaFoundationExamples.Fixtures 
 
Public _result As Boolean = False 
Public _form As PlayCtrlForm = New PlayCtrlForm() 
Private _duration As Double = 0.0 
Private _currentPos As Double = -1 
 
Public Sub PlayExample() 
   ' reference the play control 
   Dim playctrl As PlayCtrl = _form.PlayCtrl 
 
   ' input file 
   Dim inFile As String = Path.Combine(LEAD_VARS.MediaDir, "PlayCtrl_Source.avi") 
 
   Try 
      ' set autostart to false 
      playctrl.AutoStart = False 
 
      ' set the play count to 2 
      playctrl.PlayCount = 2 
 
      ' set our source media file 
      playctrl.SourceFile = inFile 
 
      ' get the reported duration 
      _duration = playctrl.Duration 
 
      ' set the playback rate to 2x 
      If playctrl.IsRateSupported(2.0) Then 
         playctrl.Rate = 2.0 
      End If 
 
      ' set event handler to get tracking position changes 
      AddHandler playctrl.TrackingPositionChanged, AddressOf PlayCtrl_TrackingPositionChanged 
 
      ' run it! 
      playctrl.Run() 
   Catch e1 As Exception 
      _result = False 
   End Try 
 
   ' we'll loop on the state and pump messages for this example. 
   ' but you should not need to if running from a Windows Forms application. 
   Do While playctrl.State = PlayState.Running 
      Application.DoEvents() 
   Loop 
 
   ' set the result to determine if the reported duration 
   ' is the same as the final position from tracking 
   _result = (_duration = _currentPos AndAlso _duration > 0.0) 
End Sub 
 
Private Sub PlayCtrl_TrackingPositionChanged(ByVal sender As Object, ByVal e As TrackingPositionChangedEventArgs) 
   ' get the frame and tracking positions for demonstration only 
   Dim frame As Integer = _form.PlayCtrl.CurrentFramePosition 
   Dim tracking As Integer = _form.PlayCtrl.CurrentTrackingPosition 
 
   ' get the current position 
   _currentPos = Math.Max(_currentPos, _form.PlayCtrl.CurrentPosition) 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const MediaDir As String = "C:\LEADTOOLS21\Media" 
End Class 
Requirements

Target Platforms

See Also

Reference

PlayCtrl Class

PlayCtrl Members

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.MediaFoundation Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.