Skip to main content

SourceSync-Moment

The Moment module is a crucial component of the SourceSync SDK that handles time-based content metadata.

Installation

The Moment Library is included in the main SourceSync SDK package but can be installed independently:

npm install sourcesync-sdk

or

npm install @sourcesync-sdk/moment @sourcesync-sdk/app

Key Concepts

Moments

Moments are time-based events or content that are synchronized with your video timeline. They can trigger actions, display overlays, or update content at specific points during video playback.

Moment Selector

The Moment Selector is a tool for retrieving and managing moments based on various criteria such as time, tags, or custom properties.

Usage

First, import and create a Moment Selector:

import { initializeApp } from 'sourcesync-sdk/app';
import { createMomentSelector } from 'sourcesync-sdk/moment';

const app = await initializeApp({
appKey: 'YOUR_API_KEY',
env: 'prod'
});

const momentSelector = createMomentSelector(app, {
// options
});

API Reference

createMomentSelector(app: SourceSyncApp, options: MomentSelectorOptions): MomentSelector

Creates a new Moment Selector instance.

Parameters:

  • app: The SourceSync app instance
  • options: Configuration options for the Moment Selector

Returns: A MomentSelector instance

MomentSelector

Methods:

  • getMoment(id: string): Promise<Moment>: Retrieves a specific moment by ID
  • getMoments(options: GetMomentsOptions): Promise<Moment[]>: Retrieves multiple moments based on specified criteria
  • getNextMoment(currentTime: number): Promise<Moment | null>: Gets the next moment after the specified time

Moment

Properties:

  • id: Unique identifier for the moment
  • startTime: The time (in seconds) when the moment should trigger
  • duration: How long the moment should last (in seconds)
  • data: Custom data associated with the moment

Methods:

  • isActive(currentTime: number): boolean: Checks if the moment is active at the given time

Example Usage

import { initializeApp } from 'sourcesync-sdk/app';
import { createMomentSelector } from 'sourcesync-sdk/moment';

async function setupMoments() {
const app = await initializeApp({
appKey: 'YOUR_API_KEY',
env: 'prod'
});

const momentSelector = createMomentSelector(app, {
mediaId: 'your-video-id'
});

// Get all moments for the video
const allMoments = await momentSelector.getMoments();

// Get the next moment from a specific time
const currentTime = 30; // 30 seconds into the video
const nextMoment = await momentSelector.getNextMoment(currentTime);

if (nextMoment) {
console.log(`Next moment starts at ${nextMoment.startTime} seconds`);
}

// Check if a moment is active
video.addEventListener('timeupdate', () => {
allMoments.forEach(moment => {
if (moment.isActive(video.currentTime)) {
console.log(`Moment ${moment.id} is active`);
// Trigger your moment-specific logic here
}
});
});
}

setupMoments();

Best Practices

  1. Create the Moment Selector after initializing the main SourceSync app.
  2. Use the getNextMoment method for efficient moment tracking during video playback.
  3. Implement error handling when working with asynchronous moment methods.
  4. Consider caching moment data for improved performance in long-form videos.

For integration with interactive overlays and user interactions, refer to the Render Library documentation.