private System.Windows.Threading.DispatcherTimer timer =
new System.Windows.Threading.DispatcherTimer();
public MainPage()
{
InitializeComponent();
//one second
timer.Interval = new TimeSpan(0,0,1);
timer.Start();
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
switch (videoPlayer.CurrentState)
{
case MediaElementState.Playing:
case MediaElementState.Buffering:
if (videoPlayer.NaturalDuration.HasTimeSpan)
{
double total = videoPlayer.NaturalDuration.TimeSpan.TotalMilliseconds;
if (total > 0.0)
{
double elapsed = videoPlayer.Position.TotalMilliseconds;
progressBar.UpdatePlaybackProgress(
100.0 * elapsed / total);
}
}
break;
default:
//do nothing
break;
}
}