video playback speed control

pull/20/head
cosmonaut 2022-07-29 18:55:19 -07:00
parent 3966a0c4ea
commit ad0c86e8f6
1 changed files with 11 additions and 4 deletions

View File

@ -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(