Exemplo n.º 1
0
        public void StopRecording()
        {
            if (recording != null)
            {
                recording.Stop();
                recording.Dispose();
                recording = null;
            }
            if (client != null)
            {
                client.DisconnectFromService();
                client.Dispose();
                client = null;
            }

            LogConsole.WriteLine("Recording stopped");
        }
Exemplo n.º 2
0
 /// <summary>
 /// 开始录制xef文件
 /// </summary>
 /// <param name="filePath">xef文件路径</param>
 public void StartRecordClip(object filePath)
 {
     try
     {
         using (KStudioClient client = KStudio.CreateClient())
         {
             client.ConnectToService();
             KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
             //streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
             streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
             streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
             streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
             //streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
             using (KStudioRecording recording = client.CreateRecording((string)filePath, streamCollection))
             {
                 recording.Start();
                 SharpAvi.IsCreateRecord = true;
                 SharpAvi.IsRecording    = true;
                 while (recording.State == KStudioRecordingState.Recording)
                 {
                     //Flag为1时调出循环,结束录像
                     if (_flag == 1)
                     {
                         break;
                     }
                 }
                 SharpAvi.IsStopRecord = true;
                 recording.Stop();
                 recording.Dispose();
             }
             client.DisconnectFromService();
             client.Dispose();
             _flag = 0;
         }
     }
     catch
     {
         _flag  = 0;
         _flag1 = 1;
         SharpAvi.IsStopRecord = true;
         MessageBox.Show("视频录制出现异常");
     }
 }
Exemplo n.º 3
0
        public void RecordClip()
        {
            //Console.WriteLine("the thing filepath is"+thing.FilePath);
            string xefname = filePath + MainWindow.textbox + ".xef";

            // Make sure to have enough disk space for the recording
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            //const string c = @"G:\";
            try
            {
                foreach (DriveInfo d in allDrives)
                {
                    if (d.IsReady && d.Name == c)
                    {
                        long totfreespace = d.TotalFreeSpace;
                        if (totfreespace < minimum_size)
                        {
                            string size = (minimum_size / 1E9).ToString();
                            mes = "Not enough disk space to record Kinect video, Available memory less than "
                                  + size + " GB";
                            throw new System.ArgumentException(mes);
                        }
                    }
                }
            }
            catch (ArgumentException exx)
            {
                Console.WriteLine("{0} Exception caught.", exx);
                done = true;
                //act_rec.Reset();
                rec_error = true;

                if (exx.Message != mes)
                {
                    // Let's restart the Kinect video service
                    // This service once stopped does not seem to restart automatically
                    Process[] kstu = Process.GetProcessesByName("KStudioHostService");
                    ///  kstu[0].Kill(); // Kill the process
                    kstu = Process.GetProcessesByName("KinectService");
                    kstu[0].Kill();
                }

                while (MessageBox.Show(exx.Message, "ERROR", MessageBoxButton.OK,
                                       MessageBoxImage.Error) != MessageBoxResult.OK)
                {
                    Thread.Sleep(20);
                }

                // Reset the recording error before exiting
                rec_error = false;
                return;
            }

            // try
            //  {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
                //streamCollection.Add(KStudioEventStreamDataTypeIds.CompressedColor);

                try
                {
                    Console.WriteLine("now the filepath is " + filePath);
                    using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                    {
                        // Introduce a timer to make sure that the recording is never longer than expected
                        //  act_rec.Start();

                        //recording.StartTimed(duration);
                        recording.Start();

                        while (recording.Duration.TotalMilliseconds < dur && done == false)
                        {
                            Thread.Sleep(30);
                            //int si = (int)recording.BufferInUseSizeMegabytes;
                            // Console.WriteLine("Recording Buffer in Megabytes {0} ", si);
                        }

                        recording.Stop();
                        recording.Dispose();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                    done      = true;
                    rec_error = true;

                    while (MessageBox.Show("ERROR", e.Message, MessageBoxButton.OK, MessageBoxImage.Error) != MessageBoxResult.OK)
                    {
                        Thread.Sleep(20);
                    }


                    // Reset the recording error before exiting
                    rec_error = false;

                    return;
                }
                finally
                {
                    Thread.Sleep(100);
                    client.DisconnectFromService();
                }
            }

            // Make sure to reset the bool done variable once recording is done
        }