Class: PlaybackDevice

PlaybackDevice()

This class is used to playback the file recorded by RecorderDevice There are 2 ways for users to create a PlaybackDevice:

 Syntax 1: PlaybackDevice.from(device)
 Syntax 2: Context.loadDevice(filePath)
Syntax 1 is to convert an existing device to a PlaybackDevice which can only be applied to device that can be converted. Here is an example:

 const file = 'record.bag';
 let cfg = new rs2.Config();
 cfg.enableDeviceFromFile(file);
 let pipe = new rs2.Pipeline();
 pipe.start(cfg);
 let device = pipe.getActiveProfile().getDevice();
 let playback = rs2.PlaybackDevice.from(device);

 for (let i = 0; i < 10; i++) {
   let frames = pipe.waitForFrames();
 }

 pipe.stop();
 rs2.cleanup();
Syntax 2 is to create a PlaybackDevice through Context. Here is an example:

 let ctx = new rs2.Context();
 // load the recorded file
 let dev = ctx.loadDevice('record.bag');
 let sensors = dev.querySensors();
 let sensor = sensors[0];
 let profiles = sensor.getStreamProfiles();
 let cnt = 0;

 // when received 'stopped' status, stop playback
 dev.setStatusChangedCallback((status) => {
   console.log('playback status: ', status);
   if (status.description === 'stopped') {
     dev.stop();
     ctx.unloadDevice('record.bag');
     rs2.cleanup();
     console.log('Playback ', cnt, ' frames');
   }
 });

 // start playback
 sensor.open(profiles);
 sensor.start((frame) => {
   cnt ++;
 });

Constructor

new PlaybackDevice()

Source:
See:

Extends

Members

currentStatus

Returns the current state of the playback device
Source:

duration

Retrieves the total duration of the file, unit is millisecond.
Source:

fileName

Retrieves the name of the playback file
Source:

first

Get the first sensor
Overrides:
Source:

isRealTime

Indicates if playback is in real time mode or non real time In real time mode, playback will play the same way the file was recorded. If the application takes too long to handle the callback, frames may be dropped. In non real time mode, playback will wait for each callback to finish handling the data before reading the next frame. In this mode no frames will be dropped, and the application controls the frame rate of the playback (according to the callback handler duration).
Source:

isRealTime

Set the playback to work in real time or non real time
Source:

isValid

Check if everything is OK, e.g. if the device object is connected to underlying hardware
Overrides:
Source:

position

Retrieves the current position of the playback in the file in terms of time. Unit is millisecond
Source:

Methods

(static) from(device) → {PlaybackDevice|undefined}

Create a PlaybackDevice from another device
Parameters:
Name Type Description
device Device another existing device that can be converted to a PlaybackDevice
Source:
Returns:
If the the input device can be converted to a PlaybackDevice, return the newly created PlaybackDevice, otherwise, undefined is returned.
Type
PlaybackDevice | undefined

destroy()

Release resources associated with the object
Overrides:
Source:

getCameraInfo(infoopt) → {CameraInfoObject|String|undefined}

Get camera information There are 2 acceptable forms of syntax:

 Syntax 1. getCameraInfo()
 Syntax 2. getCameraInfo(info)
Parameters:
Name Type Attributes Description
info String | Integer <optional>
the camera_info type, see camera_info for available values
Overrides:
Source:
Returns:
if no argument is provided, {CameraInfoObject} is returned. If a camera_info is provided, the specific camera info value string is returned.
Type
CameraInfoObject | String | undefined

pause() → {undefined}

Pauses the playback Calling pause() in "paused" status does nothing If pause() is called while playback status is "playing" or "stopped", the playback will not play until resume() is called
Source:
Returns:
Type
undefined

querySensors() → {Array.<Sensor>}

get an array of adjacent sensors, sharing the same physical parent composite device
Overrides:
Source:
Returns:
Type
Array.<Sensor>

reset() → {undefined}

Send hardware reset request to the device.
Overrides:
Source:
Returns:
Type
undefined

resume() → {undefined}

Resumes the playback Calling resume() while playback status is "playing" or "stopped" does nothing
Source:
Returns:
Type
undefined

seek(time) → {undefined}

Sets the playback to a specified time point of the played data
Parameters:
Name Type Description
time time the target time to seek to, unit is millisecond
Source:
Returns:
Type
undefined

setPlaybackSpeed(speed)

Set the playing speed
Parameters:
Name Type Description
speed Float indicates a multiplication of the speed to play (e.g: 1 = normal, 0.5 half normal speed)
Source:

setStatusChangedCallback(callback) → {undefined}

Register a callback to receive the playback device's status changes
Parameters:
Name Type Description
callback StatusChangedCallback the callback method
Source:
Returns:
Type
undefined

stop() → {undefined}

Stops playback
Source:
Returns:
Type
undefined

supportsCameraInfo(info) → {Boolean|undefined}

Check if specific camera info is supported.
Parameters:
Name Type Description
info String | Integer info type to query. See camera_info for available values
Overrides:
Source:
See:
Returns:
Returns undefined if an invalid info type was specified.
Type
Boolean | undefined
Example

Example of 3 equivalent calls of the same query

device.supportsCameraInfo('name');
device.supportsCameraInfo(realsense2.camera_info.camera_info_name);
device.supportsCameraInfo(realsense2.camera_info.CAMERA_INFO_NAME);