public void Start() { Stop(); IsFinished = false; cancellationTokenSource = new CancellationTokenSource(); var token = cancellationTokenSource.Token; Task.Factory.StartNew(() => { foreach (var frame in frames) { Thread.Sleep(TimeSpan.FromMilliseconds(frame.TimeStamp)); if (token.IsCancellationRequested) { break; } if (FrameReady != null) { FrameReady(frame); } } IsFinished = true; ReplayFinished.Raise(); }, token); }
private void SendReplayFinished() { ReplayFinished?.Invoke(this, null); }
public KinectReplay(string fileName) { stream = File.OpenRead(fileName); reader = new BinaryReader(stream); synchronizationContext = SynchronizationContext.Current; Options = (KinectRecordOptions)reader.ReadInt32(); var paramsArrayLength = reader.ReadInt32(); var colorToDepthRelationalParameters = reader.ReadBytes(paramsArrayLength); CoordinateMapper = new CoordinateMapper(colorToDepthRelationalParameters); if ((Options & KinectRecordOptions.Frames) != 0) { framesReplay = new ReplayAllFramesSystem(); framesReplay.AddFrames(reader); framesReplay.ReplayFinished += () => synchronizationContext.Send(state => ReplayFinished.Raise(), null); } if ((Options & KinectRecordOptions.Audio) != 0) { var audioFilePath = Path.ChangeExtension(fileName, ".wav"); if (File.Exists(audioFilePath)) { AudioFilePath = audioFilePath; } } }