Last reviewed: 3/23/2024 9:01:32 AM

Event Handling

To receive sensor data, status, and error messages, applications receive event notifications.

EventEvent ArgumentsDescription
ApiErrorChantAPIErrorEventArgsNotifies the application of an API error
AudioDestinationStartAudioEventArgsNotifies the application of the audio output start
AudioDestinationStopAudioEventArgsNotifies the application of the audio output stop
AudioSourceStartAudioEventArgsNotifies the application of the audio input start
AudioSourceStopAudioEventArgsNotifies the application of the audio input stop
AudioBeamFrameArrivedAudioBeamFrameArrivedEventArgsNotifies the application when a audio beam frame arrives
BeamAngleChangedBeamAngleChangedEventArgsNotifies the application when the beam angle changes
BeamAngleConfidenceChangedBeamAngleConfidenceChangedEventArgsNotifies the application when the beam angle confidence changes
BodyFrameArrivedBodyFrameArrivedEventArgsNotifies the application when a body frame arrives
BodyIndexFrameArrivedBodyIndexFrameArrivedEventArgsNotifies the application when a body index frame arrives
ColorFrameArrivedColorFrameArrivedEventArgsNotifies the application when a color frame arrives
CoordinateMappingChangedCoordinateMappingChangedEventArgsNotifies the application the synthesizer has generated a sentence boundary in the current synthesized speech audio
DepthFrameArrivedDepthFrameArrivedEventArgsNotifies the application when a depth frame arrives
FrameCapturedFrameCapturedEventArgsNotifies the application when a frame is captured
InfraredFrameArrivedInfraredFrameArrivedEventArgsNotifies the application when an infrared frame arrives
IsAvailableChangedIsAvailableChangedEventArgsNotifies the application when a sensor availability changes
LongExposureInfraredFrameArrivedLongExposureInfraredFrameArrivedEventArgsNotifies the application when a long exposure infrared frame arrives
MultiSourceFrameArrivedMultiSourceFrameArrivedEventArgsNotifies the application when a multi source frame arrives
PropertyChangedPropertyChangedEventArgsNotifies the application when a sensor property value changes
RelativeTimeChangedRelativeTimeChangedEventArgsNotifies the application when relative time changes

Some events provide data values that are returned in argument objects.

  • AudioBeamFrameArrivedEventArgs
    • FrameReference - The reference to the audio beam frame for the FrameArrived event
  • AudioEventArgs
    • File - File name
  • BeamAngleChangedEventArgs
    • Angle - Beam angle value
  • BeamAngleConfidenceChangedEventArgs
    • Confidence - Beam angle confidence value
  • BodyFrameArrivedEventArgs
    • FrameReference - The reference to the body frame for the FrameArrived event
  • BodyIndexFrameArrivedEventArgs
    • FrameReference - The reference to the body index frame for the FrameArrived event
  • ChantAPIErrorEventArgs
    • Function - API funtion name
    • Message - API error message
    • RC - API error return code
  • ColorFrameArrivedEventArgs
    • FrameReference - The reference to the color frame for the FrameArrived event.
  • CoordinateMappingChangedEventArgs
    • No arguments
  • DepthFrameArrivedEventArgs
    • FrameReference - The reference to the depth frame for the FrameArrived event
  • FrameCapturedEventArgs
    • FrameStatus - Frame captured status
    • FrameType - Frame source type
    • RelativeTime - Relative time
  • InfraredFrameArrivedEventArgs
    • FrameReference - The reference to the infrared frame for the FrameArrived event
  • IsAvailableChangedEventArgs
    • IsAvailable - Availability value
  • LongExposureInfraredFrameArrived
    • FrameReference - The reference to the infrared frame for the FrameArrived event
  • MultiSourceFrameArrived
    • FrameReference - The reference to the multi source frame for the FrameArrived event
  • PropertyChanged
    • PropertyName - The property name
  • RelativeTimeChanged
    • RelativeTime - Relative time

Event notifications are recieved in callback routines as follows:


// Create KinectSensor
_Sensor = _KinesicsKit.CreateKinectSensor();
if (_Sensor != null)
{
    // Setup event callback handler
    _Sensor.MultiSourceFrameArrived += this.NKinectSensor_MultiSourceFrameArrived;
}
    

// Static event handler declaration
void CALLBACK MultiSourceFrameArrived(void* Sender, CMultiSourceFrameArrivedEventArgs* Args);
// Create recognizer
_Sensor = _KinesicsKit->CreateKinectSensor();
if (_Sensor != NULL)
{
    // Register Event Handlers
    _Sensor->SetMultiSourceFrameArrived(MultiSourceFrameArrived);
}
    

// Static event handler declaration
void CALLBACK MultiSourceFrameArrived(void* Sender, CMultiSourceFrameArrivedEventArgs* Args);
// Create recognizer
_Sensor = _KinesicsKit->CreateKinectSensor();
if (_Sensor != NULL)
{
    // Register Event Handlers
    _Sensor->SetMultiSourceFrameArrived(MultiSourceFrameArrived);
}
    

procedure MultiSourceFrameArrived(Sender: TObject; Args: TMultiSourceFrameArrivedEventArgs);
// Create recognizer
_Sensor := _KinesicsKit.CreateKinectSensor();
if (_Sensor <> nil) then
begin
      // Register Event Handlers
    _Sensor.MultiSourceFrameArrived := MultiSourceFrameArrived;
end;
    

// Add implements for event handlers
public class Frame1 extends JFrame implements JChantKinesicsKitEvents
// Create KinectSensor
_Sensor = _KinesicsKit.createKinectSensor();
if (_Sensor != null)
{
    // Set the callback
    _Sensor.setChantKinesicsKitEvents(this);
    // Register Callbacks for visual cues.
    _Sensor.registerCallback(ChantKinesicsKitCallback.CCKSMultiSourceFrameArrived);
}
    

_KinesicsKit = New NKinesicsKit()
// Declaring the event handlers routines with Handles clause in VB automatically registers for the event notifications
Public Sub NKinectSensor_MultiSourceFrameArrived(ByVal sender As System.Object, ByVal e As MultiSourceFrameArrivedEventArgs) Handles _Sensor.MultiSourceFrameArrived
    

The KinectSensor object sends all notifications to the event handlers. All event data is contained in a arguments object.


private void NKinectSensor_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
{
    MultiSourceFrameReference multiSourceFrameReference = e.FrameReference;
    if (multiSourceFrameReference != null)
    {
        MultiSourceFrame multiSourceFrame = multiSourceFrameReference.AcquireFrame();
        if (multiSourceFrame != null)
        {
            ...
            multiSourceFrame.Dispose();
        }
        multiSourceFrameReference.Dispose();
    }
}
    

void CALLBACK MultiSourceFrameArrived(void* Sender, CMultiSourceFrameArrivedEventArgs* Args)
{
    CMultiSourceFrameReference* pMultiSourceFrameReference = Args->GetFrameReference();
    if (pMultiSourceFrameReference != NULL)
    {
        CMultiSourceFrame* pMultiSourceFrame = pMultiSourceFrameReference->AcquireFrame();
        if (pMultiSourceFrame != NULL)
        {
            ...
            delete pMultiSourceFrame;
        }
        delete pMultiSourceFrameReference;
    }
}
    

void CALLBACK MultiSourceFrameArrived(void* Sender, CMultiSourceFrameArrivedEventArgs* Args)
{
    CMultiSourceFrameReference* pMultiSourceFrameReference = Args->GetFrameReference();
    if (pMultiSourceFrameReference != NULL)
    {
        CMultiSourceFrame* pMultiSourceFrame = pMultiSourceFrameReference->AcquireFrame();
        if (pMultiSourceFrame != NULL)
        {
            ...
            delete pMultiSourceFrame;
        }
        delete pMultiSourceFrameReference;
    }
}
    

procedure TForm1.MultiSourceFrameArrived(Sender: TObject; Args: TMultiSourceFrameArrivedEventArgs);
var
  multiSourceFrameReference: TMultiSourceFrameReference;
  multiSourceFrame: TMultiSourceFrame;
begin
    multiSourceFrameReference := Args.FrameReference;
    if (multiSourceFrameReference <> nil) then
    begin
      multiSourceFrame := multiSourceFrameReference.AcquireFrame;
      if (multiSourceFrame <> nil) then
      begin
        ...
        multiSourceFrame.Destroy;
      end;
      multiSourceFrameReference.Destroy;
    end;
end;
    

// Notifies the application when a multi source frame arrives.
public void multiSourceFrameArrived(Object sender, MultiSourceFrameArrivedEventArgs args)
{
    MultiSourceFrameReference multiSourceFrameReference = args.getFrameReference();
    if (multiSourceFrameReference != null)
    {
        MultiSourceFrame multiSourceFrame = multiSourceFrameReference.acquireFrame();
        if (multiSourceFrame != null)
        {
            ...
            multiSourceFrame.dispose();
        }
        multiSourceFrameReference.dispose();
    }
}
    

Public Sub NKinectSensor_MultiSourceFrameArrived(ByVal sender As System.Object, ByVal e As MultiSourceFrameArrivedEventArgs) Handles _Sensor.MultiSourceFrameArrived
    Dim multiSourceFrameReference As MultiSourceFrameReference = e.FrameReference
    If Not (multiSourceFrameReference Is Nothing) Then
        Dim multiSourceFrame As MultiSourceFrame = multiSourceFrameReference.AcquireFrame()
        If Not (multiSourceFrame Is Nothing) Then
            ...
            multiSourceFrame.Dispose()
        End If
        multiSourceFrameReference.Dispose()
    End If
End Sub