Recording and Playing Back .XEF Files Using XStudio API

The following code uses the XStudio API to record NUI streams to a .XEF file and then play back the file.

To use XStudio API to record and play back data:

  1. Include the following:
    #include "XStudio.h"
    using namespace Microsoft::Xbox::Tools::XStudio;  
    
  2. Create an XStudio session instance with XStudioCreateSession:
    IXStudioSession*    m_pXStudioSession;
    XStudioCreateSession(&m_pXStudioSession);  
    
  3. Create a recorder instance with IXStudioSession::CreateRecording Method. Use IXStudioRecording::Start Method to start recording NUI streams to a specified .XEF file either on the console or the development PC; and use IXStudioRecording::Stop Method to stop the recording. The following code records the default XStudio recording streams to a specified .XEF file on the console.
    IXStudioRecording*  m_pRecorder;
    IXStudioPlayback*   m_pPlayer;
          
    // Create a recorder instance
    if ( FAILED( m_pXStudioSession->CreateRecording( 
        XSTUDIO_LOCATION_DEVKIT,                           // The .XEF file resides on the console.
        m_RecordingPath,                                   // A fully-qualified .XEF file name.
        XSTUDIO_DEFAULT_NUI_RECORDING_STREAMS,             // This includes the depth, active IR, and body streams.                                                          
        ARRAYSIZE( XSTUDIO_DEFAULT_NUI_RECORDING_STREAMS ),
        &m_pRecorder ) )                                   // A recorder instance.
    )
    {
        m_pRecorder->Stop();
        m_pRecorder->Release();
        m_pRecorder = NULL;
        // Add other error handling logic.
    }
          
    m_pRecorder->Start();  
    
  4. Create a player instance with IXStudioSession::CreatePlayback Method. Use IXStudioRecording::Start Method to start the playback; and use IXStudioRecording::Stop Method to stop the playback. The following code uses the default XStudio playback streams.
           
    // Create a player instance 
    if (FAILED( m_pXStudioSession->CreatePlayback( 
        XSTUDIO_LOCATION_DEVKIT,                           // The .XEF file resides on the console. 
        m_RecordingPath,                                   // A fully-qualified .XEF file name.
        XSTUDIO_DEFAULT_NUI_PLAYBACK_STREAMS,              // This includes the depth and active IR streams.
        ARRAYSIZE( XSTUDIO_DEFAULT_NUI_PLAYBACK_STREAMS ),
        &m_pPlayer ) )                                     // A player instance.
        )
      {
          m_pPlayer->Stop();
          m_pPlayer->Release();
          m_pPlayer = NULL;
          // Add other error handling logic.
      }
          
      m_pPlayer->Start();  
    

For the complete code listing, see the SimpleXStudioRecordPlayback sample.