I'm following code from the kinect toolkit to record and replay frames, I know the issue is that it never recognizes a new replay_SkeletonFrameReady and thus I can't draw my recorded skeleton. Note that there is indeed data in the file which I read from (data saved also via kinect toolkit method).
void replay_SkeletonFrameReady(object sender, ReplaySkeletonFrameReadyEventArgs e)
{
//..The code never makes it to this part, why is this?
processFrame(e.SkeletonFrame);
}
private void processFrame(ReplaySkeletonFrame frame)
{
if (frame != null)
{
skeletonsReplay = new Skeleton[frame.Skeletons.Length];
skeletonsReplay = frame.Skeletons;
Console.WriteLine("attempting draw");
drawMe(); //..Function that draws skeleton
}
}
private void LaunchReplay()
{
Console.WriteLine("replay launched");
Stream readFS = File.OpenRead(@Global.localDirectory +
"\\localStorage\\MySwing.replay");
replay = new KinectReplay(readFS);
//..This line of code should cause the first function to be called right?
replay.SkeletonFrameReady += replay_SkeletonFrameReady;
replay.Start();
}
As the Kinect Toolbox is open source, we have the benefit of seeing what is going on internally.
When you initialize the KinectReplay object by passing it a Stream, the class will look in that file and see which streams were saved into the file (this was specified when you used the KinectRecorder and passed it a KinectRecorderOptions enum instance. The KinectReplay constructor will then read the entire file adding skeleton/color/depth frames to internal collections as it finds them.
When you call the Start method, the KinectReplay system will mimic the recording down to the millisecond providing the same frame timings that were initially recorded. For example, look in the ReplaySystem Start method and you will see that (in a background thread* - read: wont keep your process running if its the last thread alive) it does a thread sleep for the timestamp in the first frame. In my case, the first skeleton frame was not seen for 2752 milliseconds so that was the first sleep. It may be that your code is going out of scope before the replay system wakes up and sends out the frames.
*Note: it may not be a background thread, it is technically an abstract task that can choose any parallelism mechanism..