Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Prefer using TimeSpan.FromMilliseconds rather than multiplying by 10000
Browse files Browse the repository at this point in the history
Using the TimeChanged event rather than PositionChanged to display
current time in WinForms sample
  • Loading branch information
jeremyVignelles committed Oct 14, 2018
1 parent 12e28de commit 57e3ec3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Samples/Samples.WinForms.Advanced/Sample.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/Samples/Samples.WinForms.Advanced/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ private void OnButtonPauseClicked(object sender, EventArgs e)

private void OnVlcMediaLengthChanged(object sender, VlcMediaPlayerLengthChangedEventArgs e)
{
myLblMediaLength.InvokeIfRequired(l => l.Text = new DateTime(new TimeSpan(e.NewLength).Ticks).ToString("T"));
myLblMediaLength.InvokeIfRequired(l => l.Text = TimeSpan.FromMilliseconds(e.NewLength).ToString(@"hh\:mm\:ss"));
}

private void OnVlcPositionChanged(object sender, VlcMediaPlayerPositionChangedEventArgs e)
private void OnVlcTimeChanged(object sender, VlcMediaPlayerTimeChangedEventArgs e)
{
var position = myVlcControl.GetCurrentMedia().Duration.Ticks * e.NewPosition;
myLblVlcPosition.InvokeIfRequired(l => l.Text = new DateTime((long)position).ToString("T"));
myLblVlcPosition.InvokeIfRequired(l => l.Text = TimeSpan.FromMilliseconds(e.NewTime).ToString(@"hh\:mm\:ss"));
}

private void OnVlcPaused(object sender, VlcMediaPlayerPausedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Vlc.DotNet.Core/VlcMedia/VlcMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public MediaStates State

public TimeSpan Duration
{
get { return new TimeSpan(myVlcMediaPlayer.Manager.GetMediaDuration(MediaInstance) * 10000); }
get { return TimeSpan.FromMilliseconds(myVlcMediaPlayer.Manager.GetMediaDuration(MediaInstance)); }
}

public void Dispose()
Expand Down

0 comments on commit 57e3ec3

Please sign in to comment.