예제 #1
0
        /// <summary>
        /// Converts the BodyIndexFrameArrived event to an observable sequence.
        /// </summary>
        /// <param name="kinectSensor">The kinect sensor.</param>
        /// <returns>The observable sequence.</returns>
        public static IObservable <BodyIndexFrameArrivedEventArgs> BodyIndexFrameArrivedObservable(this KinectSensor kinectSensor)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            return(Observable.Create <BodyIndexFrameArrivedEventArgs>(observer =>
            {
                var reader = kinectSensor.BodyIndexFrameSource.OpenReader();

                var disposable = kinectSensor.BodyIndexFrameArrivedObservable(reader)
                                 .Subscribe(x => observer.OnNext(x),
                                            e => observer.OnError(e),
                                            () => observer.OnCompleted());

                return new CompositeDisposable {
                    disposable, reader
                };
            }));
        }