1. Home
  2. Docs
  3. Video
  4. Video player

Video player

The video playback module allows you to reproduce a video you captured using the Video Recorder. The video player reads color, depth, skeleton, IMU, and floor data from the disk. All these data types are stored in binary form. The video player should know the absolute path to the folder containing the video data.

You don’t need an active camera to play a video.

Example

Here is a basic C# example of playing a video:

using LightBuzz.BodyTracking.Video;
public class VideoPlaybackDemo : MonoBehaviour
{
    private readonly VideoPlayer _player = new VideoPlayer();
    private void Start()
    {
        // First, specify the location of the video.
        _player.Folder = "/Users/lightbuzz/videos/my_video";
        // Set the loop and speed values
        _player.Loop = true;
        _player.Speed = 1.0f;
        // Now, start playback!
        _player.Start();
    }
    private void Update()
    {
        FrameData frame = _player.Update();
        if (frame != null)
        {
            // Grab frame data just like you'd do with a live camera!
            byte[] color = frame.ColorData;
            ushort[] depth = frame.DepthData;
            List<Body> bodies = frame.BpdyData;
        }
    }
    private void OnDestroy()
    {
        // Stop playback.
        _player.Stop();
        // Dispose the player when it's no longer necessary.
        _player.Dispose();
    }
}

Methods

The video player only includes four methods with straightforward functionality.

Start()

Starts playing the video.

Stop()

Stops video playback.

Update()

Returns the current frame of the video. If the video is paused, this method will return a null frame object.

Dispose()

Clears unmanaged resources and closes any background threads. Call Dispose() when you no longer need the video player. In Unity, you should always call Dispose() when your video GameObject is disabled or removed from the hierarchy.

Properties

The video player provides the following properties:

IsPlaying (read-only)

Returns whether the video is currently playing. When true, the video player could be streaming frames or remaining paused.

Settings (read-only)

Returns the imported video configuration options. The configuration includes the following settings:

  • Color resolution
  • Depth resolution
  • Color format

Timestamps (read-only)

A list of every frame timestamp in descending order. Each timestamp is a unique DateTime object.

FrameCount (read-only)

The number of captured frames.

FrameRate (read-only)

The average frame rate of the video, e.g., 30 frames per second.

Duration (read-only)

The duration of the video expressed as a TimeSpan structure.

TimeElapsed (read-only)

The time elapsed between the current and the previous frame.

Folder

The absolute path to the folder containing the video data.

IsPaused

Gets or sets the state of the player: paused or not. Use this property to pause playback.

Index

Gets or sets the position of the current frame. The minimum index value is 0, while the maximum value is the number of frames (minus one). You can assign the position explicitly to jump to a specific frame.

Seek

Represents the frame index as a normalized value between 0.0 and 1.0. Use this property to move to a particular position in the video without knowing the index. For example, if you want to go to the middle of the video, set the Seek value to 0.5.

Speed

Gets or sets the playback speed. The default speed is 1. Lower values will make the video play slower, while greater values will make the video play faster.

Loop

Use this value to loop the video. When true, the video automatically replays when finished.

How can we help?