public void GetDepthArrayTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    DepthStream stream = DepthStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        DFrame frame = (DFrame)stream.GetFrame();
                        if (frame != null)
                        {
                            //ushort[] testArr = frame.GetDepthArray();
                            //System.Diagnostics.////Debug.WriteLine("Test Arr length : " + testArr.Length);
                            //Assert.IsNotNull(testArr);
                        }
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
                client.DisconnectFromService();
            }
        }
Example #2
0
        private void PlayClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();


                KStudioPlaybackFlags flags = KStudioPlaybackFlags.IgnoreOptionalStreams;
                playback = client.CreatePlayback(filePath, flags);
                using (playback)
                {
                    playback.PropertyChanged += Recording_PropertyChanged;
                    playback.StateChanged    += Playback_StateChanged;
                    playback.LoopCount        = 10000;
                    playback.Start();

                    FRecordTotalDuration[0] = playback.Duration.TotalSeconds;

                    while ((playback.State == KStudioPlaybackState.Playing) || (playback.State == KStudioPlaybackState.Paused) && (doPlay))
                    {
                        Thread.Sleep(50);
                    }
                    playback.Stop();
                }
                client.DisconnectFromService();
            }
        }
        private void PlayClip(string filePath, bool startpaused)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioPlaybackFlags flags = KStudioPlaybackFlags.IgnoreOptionalStreams;
                try
                {
                    playback = client.CreatePlayback(filePath, flags);
                }
                catch (Exception ex)
                {
                    FLogger.Log(LogType.Debug, ex.ToString());
                }
                using (playback)
                {
                    playback.PropertyChanged += Playback_PropertyChanged;
                    playback.StateChanged    += Playback_StateChanged;

                    playback.LoopCount              = 0;
                    playback.InPointByRelativeTime  = TimeSpan.FromSeconds(FInputInPoint[0]);
                    playback.OutPointByRelativeTime = TimeSpan.FromSeconds(Math.Min(FInputOutPoint[0], playback.Duration.TotalSeconds));
                    var kStudioMetadata = playback.GetMetadata(KStudioMetadataType.Public);

                    if (startpaused)
                    {
                        playback.StartPaused();
                    }
                    else
                    {
                        playback.Start();
                    };

                    FRecordTotalDuration[0] = playback.Duration.TotalSeconds;

                    while ((playback.State == KStudioPlaybackState.Playing) || (playback.State == KStudioPlaybackState.Paused) && (doPlay))
                    {
                        if (doStep)
                        {
                            if ((playback.State == KStudioPlaybackState.Playing))
                            {
                                playback.Pause();
                            }
                            if (playback.State == KStudioPlaybackState.Paused)
                            {
                                playback.StepOnce();
                                Thread.Sleep(20);
                            }
                            doStep = false;
                        }
                        Thread.Sleep(20);
                    }
                    playback.Stop();
                }

                playback = null;
                client.DisconnectFromService();
            }
        }
Example #4
0
 /// <summary>
 /// 播放xef视频
 /// </summary>
 /// <param name="filePath">xef视频路径</param>
 public void PlaybackClip(object filePath)
 {
     ///以前的方法,不能加骨骼上去
     #region
     using (KStudioClient PlayClient = KStudio.CreateClient())
     {
         PlayClient.ConnectToService();
         using (KStudioPlayback playback = PlayClient.CreatePlayback((string)filePath))
         {
             playback.LoopCount = 0;
             playback.Start();
             Flag2 = 0;
             while (playback.State == KStudioPlaybackState.Playing)
             {
             }
             if (playback.State == KStudioPlaybackState.Error)
             {
                 Flag2 = 1;
                 throw new InvalidOperationException("Error: Playback failed!");
             }
             Flag2 = 1;
             playback.Stop();
             playback.Dispose();
         }
         PlayClient.DisconnectFromService();
         System.Windows.Forms.MessageBox.Show("回放结束");
     }
     #endregion
 }
Example #5
0
        public static void PlaybackClip(string filePath, uint loopCount)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = loopCount;
                    playback.Start();

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }

                    if (playback.State == KStudioPlaybackState.Error)
                    {
                        throw new InvalidOperationException("Error: Playback failed!");
                    }
                }

                client.DisconnectFromService();
            }
        }
Example #6
0
        public void PlaybackClip()
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = loopCount;
                    playback.Start();

                    while (done == false && playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(30);
                    }

                    if (playback.State == KStudioPlaybackState.Error)
                    {
                        throw new InvalidOperationException("Error: Playback failed!");
                    }

                    playback.Stop();
                    // Reset the value of done
                    done = false;
                }

                client.DisconnectFromService();
            }
        }
Example #7
0
        public void GetVideoBitmapTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    VideoStream stream = VideoStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        VFrame frame = (VFrame)stream.GetFrame();
                        if (frame == null)
                        {
                            continue;
                        }
                        WriteableBitmap bmp = frame.GetBitmap();
                        Assert.IsNotNull(bmp);
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Plays back a .xef file to the Kinect sensor
        /// </summary>
        /// <param name="filePath">Full path to the .xef file that should be played back to the sensor</param>
        private void PlaybackClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                // Create the playback object
                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = this.loopCount;
                    playback.Start();

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }
                }

                client.DisconnectFromService();
            }

            // Update the UI after the background playback task has completed
            this.isPlaying = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
Example #9
0
        public void VFrameTest_LT_1Sec()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            Array.Sort(files);
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                var broken = false;
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    //Console.WriteLine("Playing: {0}", files[0]);
                    playback.Start();
                    Stopwatch time = new Stopwatch();

                    VideoStream stream = VideoStream.Instance;

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        time.Start();
                        BaseFrame frame = stream.GetFrame();
                        if (time.ElapsedMilliseconds > (1 * 1000))
                        {
                            if (frame == null)
                            {
                                broken = true;
                                System.DateTime now = DateTime.Now;
                                //System.Diagnostics.////Debug.WriteLine("Failed at: {0}:{1}:{2}:{3}", now.Hour, now.Minute, now.Second, now.Millisecond);
                            }
                        }
                        Thread.Sleep(150);
                    }
                }

                client.DisconnectFromService();
                Assert.IsFalse(broken, "The frame should not be null after 1 second");
            }
        }
Example #10
0
        /// <summary>
        /// Playback a list of clips
        /// </summary>
        /// <param name="filename">ObservableCollection of VideoModel objects that contains Filename of the clip to be played.</param>
        private void PlaybackClip(ObservableCollection <VideoModel> videos)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();
                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                VideoModel video;
                int        i = 0;

                while (i < videos.Count)
                {
                    video = videos[i];

                    if (!string.IsNullOrEmpty(video.Filename))
                    {
                        _status = "Playing " + video.Filename + " - " + (i + 1) + "/" + videos.Count;

                        using (KStudioPlayback playback = client.CreatePlayback(video.Filename))
                        {
                            _isPlaying = true;
                            _stop      = false;

                            // We can use playback.StartPaused() and SeekRelativeTime to start the clip at
                            // a specific time.
                            playback.Start();


                            while (playback.State == KStudioPlaybackState.Playing)
                            {
                                Thread.Sleep(150);

                                if (_stop)
                                {
                                    playback.Stop();
                                    break;
                                }
                            }

                            _isPlaying = false;

                            if (_stop)
                            {
                                return;
                            }
                        }
                    }
                    i++;
                }
                client.DisconnectFromService();
            }
        }
Example #11
0
        private void Play()
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();


                for (int f = 0; f < fileNames.Length; f++)
                {
                    string[] nameAndLoop = fileNames[f].Split(',');
                    Dispatcher.InvokeAsync(new Action(() => this.statusBox.Text = "Playing" + nameAndLoop[0]));

                    double loopCount = 0, timeSleept = 0;

                    try
                    {
                        playback = client.CreatePlayback(nameAndLoop[0]);
                        if (nameAndLoop.Length > 1)
                        {
                            loopCount = Double.Parse(nameAndLoop[1]);
                        }
                        else
                        {
                            loopCount = 1;
                        }

                        lock (playback)
                        {
                            playback.LoopCount   = (uint)loopCount;
                            playback.EndBehavior = KStudioPlaybackEndBehavior.Stop;
                            playback.Start();
                        }

                        while (playback != null && playback.State == KStudioPlaybackState.Playing)
                        {
                            Thread.Sleep(100);
                            timeSleept += 100;
                        }
                        if (playback != null && timeSleept < playback.Duration.TotalMilliseconds)
                        {
                            MessageBox.Show("Due to an unknown failure the playback has stopped.");
                            break;
                        }
                    }
                    catch (ThreadAbortException t) {
                        Console.WriteLine(t.ToString());
                    }
                }
            }
        }
Example #12
0
        public void startPlayback(string filePath)
        {
            uint loopCount = 100;

            new System.Threading.Thread(() =>
            {
                using (_client = KStudio.CreateClient())
                {
                    _client.ConnectToService();

                    try
                    {
                        using (_playback = _client.CreatePlayback(filePath))
                        {
                            _playback.LoopCount = loopCount;
                            _playback.Start();

                            while (_playback.State == KStudioPlaybackState.Playing || _playback.State == KStudioPlaybackState.Paused)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            _playback.Dispose();
                            _playback = null;
                        }
                        _client.DisconnectFromService();
                    }
                    catch (NullReferenceException)
                    {
                        Debug.WriteLine("Don't know why");
                    }
                    catch (ArgumentException)
                    {
                        Debug.WriteLine("Don't know why");
                    }
                    catch (InvalidOperationException)
                    {
                        Debug.WriteLine("Same video can't be loaded at the same time");
                    }
                }
            }).Start();
        }
Example #13
0
        public void OpenRecording(string filePath)
        {
            client = KStudio.CreateClient();

            client.ConnectToService();

            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

            streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
            streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
            Guid Audio = new Guid(0x787c7abd, 0x9f6e, 0x4a85, 0x8d, 0x67, 0x63, 0x65, 0xff, 0x80, 0xcc, 0x69);

            streamCollection.Add(Audio);

            playback = client.CreatePlayback(filePath, streamCollection);
            playback.StateChanged += KStudioClient_Playback_StateChanged;
            playback.Start();

            OnKinectAvailabilityChanged(this, true);

            LogConsole.WriteLine("Recording opened and playing ...");
        }
        /// <summary>
        /// Playback a clip
        /// </summary>
        /// <param name="filename">Path/name of the clip to be played.</param>
        private void PlaybackClip(string filename)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

                using (KStudioPlayback playback = client.CreatePlayback(filename))
                {
                    // If the clip should not be evaluated from the begining.
                    // It should start paused.
                    if (_initialTime.Milliseconds > 0)
                    {
                        playback.StartPaused();
                        playback.SeekByRelativeTime(_initialTime);
                        playback.Resume();
                    }
                    else
                    {
                        playback.Start();
                    }

                    while (playback.State == KStudioPlaybackState.Playing && !finished)
                    {
                        Thread.Sleep(150);
                    }

                    // Finished the read of frames for calibration.
                    if (finished)
                    {
                        playback.Stop();
                    }
                }

                client.DisconnectFromService();
            }
        }
        public Task PlayClip(string filePath, uint loopCount = 0)
        {
            if (IsRecording || IsPlaying)
            {
                return(null);
            }

            _stopRequested = false;
            Task t = Task.Run(() =>
            {
                _playing = true;
                using (KStudioClient client = KStudio.CreateClient())
                {
                    client.ConnectToService();

                    using (KStudioPlayback playback = client.CreatePlayback(filePath))
                    {
                        playback.LoopCount = loopCount;
                        playback.Start();
                        while (playback.State == KStudioPlaybackState.Playing)
                        {
                            if (_stopRequested)
                            {
                                playback.Stop();
                            }
                            Thread.Sleep(50);
                        }
                    }

                    client.DisconnectFromService();
                }
                Thread.Sleep(100);
                _playing = false;
            });

            return(t);
        }
Example #16
0
        /// <summary>
        /// Run
        /// </summary>
        private void Run()
        {
            client.ConnectToService();

            using (KStudioPlayback play = client.CreatePlayback(path))
            {
                play.EndBehavior = KStudioPlaybackEndBehavior.Stop;
                play.Mode        = KStudioPlaybackMode.TimingEnabled;
                play.LoopCount   = loop;
                play.Start();

                while (play.State.Equals(KStudioPlaybackState.Playing) || play.State.Equals(KStudioPlaybackState.Paused))
                {
                    Thread.Sleep(33);

                    if (isPause && !play.State.Equals(KStudioPlaybackState.Paused))
                    {
                        play.Pause();
                    }

                    if (!isPause && play.State.Equals(KStudioPlaybackState.Paused))
                    {
                        play.Resume();
                    }

                    if (play.State.Equals(KStudioPlaybackState.Error))
                    {
                        throw new InvalidOperationException("KStudioPlayback Error");
                    }
                }

                play.Stop();
            }

            client.DisconnectFromService();
        }
Example #17
0
 public void ReplayForever()
 {
     try
     {
         using (KStudioClient client = KStudio.CreateClient())
         {
             client.ConnectToService();
             while (true)
             {
                 KStudioPlayback playback = client.CreatePlayback(this.replayFilePath);
                 playback.LoopCount = 0;
                 playback.Start();
                 this.isReplaying = true;
                 while (playback.State == KStudioPlaybackState.Playing)
                 {
                     Thread.Sleep(500);
                 }
             }
             client.DisconnectFromService();
         }
     } catch (Exception e) {
         logCallback("ReplayForever exception: " + e.Message);
     }
 }
Example #18
0
        /// <summary>
        /// Plays an event file to the Kinect service
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to event file which is targeted for playback</param>
        /// <param name="streamNames">Collection of streams to include in the playback session</param>
        /// <param name="loopCount">Number of times the playback should be repeated before stopping</param>
        public static void PlaybackClip(KStudioClient client, string filePath, IEnumerable<string> streamNames, uint loopCount)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            KStudioPlayback playback = null;

            // determine if all specified streams are valid for playback
            if (streamNames.Count<string>() > 0)
            {
                HashSet<Guid> playbackDataTypeIds = StreamSupport.ConvertStreamsToPlaybackGuids(streamNames);
                StreamSupport.VerifyStreamsForRecordAndPlayback(playbackDataTypeIds);
                Playback.VerifyStreamsForPlayback(client, filePath, playbackDataTypeIds);

                try
                {
                    KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, false);
                    playback = client.CreatePlayback(filePath, streams);
                }
                catch (Exception)
                {
                    //K4W supports uncompressed and compressed color, so if we get an error, try playing the other type
                    KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, true);
                    playback = client.CreatePlayback(filePath, streams);
                }
            }
            else
            {
                playback = client.CreatePlayback(filePath);
            }

            // begin playback
            using (playback)
            {
                playback.EndBehavior = KStudioPlaybackEndBehavior.Stop; // this is the default behavior
                playback.Mode = KStudioPlaybackMode.TimingEnabled; // this is the default behavior
                playback.LoopCount = loopCount;
                playback.Start();

                while (playback.State == KStudioPlaybackState.Playing)
                {
                    Thread.Sleep(500);
                }

                if (playback.State == KStudioPlaybackState.Error)
                {
                    throw new InvalidOperationException(Strings.ErrorPlaybackFailed);
                }
            }
        }
Example #19
0
        /// <summary>
        /// Plays an event file to the Kinect service
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to event file which is targeted for playback</param>
        /// <param name="streamNames">Collection of streams to include in the playback session</param>
        /// <param name="loopCount">Number of times the playback should be repeated before stopping</param>
        public static void PlaybackClip(KStudioClient client, string filePath, IEnumerable <string> streamNames, uint loopCount)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            KStudioPlayback playback = null;

            // determine if all specified streams are valid for playback
            if (streamNames.Count <string>() > 0)
            {
                HashSet <Guid> playbackDataTypeIds = StreamSupport.ConvertStreamsToPlaybackGuids(streamNames);
                StreamSupport.VerifyStreamsForRecordAndPlayback(playbackDataTypeIds);
                Playback.VerifyStreamsForPlayback(client, filePath, playbackDataTypeIds);

                try
                {
                    KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, false);
                    playback = client.CreatePlayback(filePath, streams);
                }
                catch (Exception)
                {
                    //K4W supports uncompressed and compressed color, so if we get an error, try playing the other type
                    KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, true);
                    playback = client.CreatePlayback(filePath, streams);
                }
            }
            else
            {
                playback = client.CreatePlayback(filePath);
            }

            // begin playback
            using (playback)
            {
                playback.EndBehavior = KStudioPlaybackEndBehavior.Stop;   // this is the default behavior
                playback.Mode        = KStudioPlaybackMode.TimingEnabled; // this is the default behavior
                playback.LoopCount   = loopCount;
                playback.Start();

                while (playback.State == KStudioPlaybackState.Playing)
                {
                    Thread.Sleep(500);
                }

                if (playback.State == KStudioPlaybackState.Error)
                {
                    throw new InvalidOperationException(Strings.ErrorPlaybackFailed);
                }
            }
        }