Skip to main content
←API Reference ←com.nianticspatial.nsdk.playback

PlaybackSession


Declaration​

class PlaybackSession

Summary​

Runs a timed loop over a [PlaybackDataset], loading one frame per tick and notifying a listener. Use [play] to begin playback and [pause] to stop; the loop wraps to frame 0 at end, and each later pass has its timestamps moved one recording's length later so they keep increasing. Call [setOnFrameListener] before [play] to receive each [PlaybackFrame]; the listener is invoked on a background thread, one frame at a time (post to the main thread before touching UI). An exception thrown by the listener is logged and playback continues; an error loading a frame is logged and stops playback.


Constructors​

constructor(dataset: PlaybackDataset)

Parameters​

NameTypeSummary
datasetPlaybackDataset
-

Functions​

NameTypeSummary
clearOnFrameListenervoid
Clears the frame listener.
currentFrameIndexInt
Current frame index (0 until [dataset][PlaybackDataset].frameCount).
currentPlaybackFramePlaybackFrame?
Last frame delivered to the listener; null before any frame or after [pause].
disposevoid
Stops playback and releases all held references. Call from the owning component's teardown
(e.g. [androidx.lifecycle.ViewModel.onCleared] or [android.app.Activity.onDestroy]) to
prevent the listener lambda from retaining a reference to a destroyed component.
After dispose, this session should not be reused.
hasDepthBoolean
Delegates to [PlaybackDataset.hasDepth].
isPlayingBoolean
True when the session has been started and not yet paused.
pausevoid
Stops the playback loop. Current index is preserved so [play] resumes from the next frame.
playvoid
Starts the playback loop on a background thread. Delivers frames every [PlaybackDataset.frameInterval] seconds;
at end of dataset wraps to index 0. No-op if already playing.
seekToStartvoid
Resets playback to the first frame. Call before [play] to begin from the beginning; safe to call while paused.
Like the wrap at the end, it moves later timestamps on so they do not go backwards.
setOnFrameListenervoid
Sets the callback invoked for each loaded frame. Call before [play].