From ad0c86e8f65a9c64534b83014c1655b7d999d05c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 29 Jul 2022 18:55:19 -0700 Subject: [PATCH] video playback speed control --- src/Video/Video.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Video/Video.cs b/src/Video/Video.cs index 9dacfe2..f2df5ad 100644 --- a/src/Video/Video.cs +++ b/src/Video/Video.cs @@ -17,9 +17,9 @@ namespace MoonWorks.Video { private IntPtr Handle; - public bool Loop { get; set; } - public bool Mute { get; set; } - public float Volume { get; set; } + public bool Loop { get; private set; } + public float Volume { get; private set; } + public float PlaybackSpeed { get; set; } public double FramesPerSecond => fps; private VideoState State = VideoState.Stopped; @@ -41,6 +41,8 @@ namespace MoonWorks.Video private Sampler LinearSampler; private Stopwatch timer; + private double lastTimestamp; + private double timeElapsed; private bool disposed; @@ -173,6 +175,8 @@ namespace MoonWorks.Video timer.Reset(); Theorafile.tf_reset(Handle); + lastTimestamp = 0; + timeElapsed = 0; State = VideoState.Stopped; } @@ -189,7 +193,10 @@ namespace MoonWorks.Video return RenderTexture; } - int thisFrame = (int) (timer.Elapsed.TotalMilliseconds / (1000.0 / FramesPerSecond)); + timeElapsed += (timer.Elapsed.TotalMilliseconds - lastTimestamp) * PlaybackSpeed; + lastTimestamp = timer.Elapsed.TotalMilliseconds; + + int thisFrame = ((int) (timeElapsed / (1000.0 / FramesPerSecond))); if (thisFrame > currentFrame) { if (Theorafile.tf_readvideo(