Track Items
Track items are the fundamental building blocks of the DesignCombo Video Editor SDK. They represent individual media elements that can be added to the timeline and manipulated.
Item Types
The SDK supports various types of track items, each with specific properties and behaviors. Items can be categorized into two main groups:
Trimable Elements
Video and audio items support trimming, allowing you to control which portion of the media is played:
- Video Items: Support
trim
anddisplay
properties - Audio Items: Support
trim
anddisplay
properties
Non-Trimable Elements
Other item types only support display timing:
- Text Items: Only
display
property - Image Items: Only
display
property - Shape Items: Only
display
property - Caption Items: Only
display
property
Text Items
Text items display text content with rich formatting options.
// Add text itemdispatch("add:text", {payload: {name: "My Text",duration: 5000, // Duration of 5 secondsdetails: {text: "Hello World",fontSize: 48,fontFamily: "Arial",color: "#ffffff",x: 100,y: 100,width: 300,height: 100,textAlign: "center",fontWeight: "bold",fontStyle: "normal",textDecoration: "none",lineHeight: 1.2,letterSpacing: 0,backgroundColor: "transparent",borderColor: "transparent",borderWidth: 0,borderRadius: 0,shadow: {color: "rgba(0,0,0,0.5)",blur: 5,offsetX: 2,offsetY: 2}},display: {from: 0, // Display from startto: 5000 // Display for 5 seconds}}});
Image Items
Image items display static images with transformation options.
// Add image itemdispatch("add:image", {payload: {name: "My Image",duration: 8000, // Duration of 8 secondsdetails: {src: "https://example.com/image.jpg",x: 0,y: 0,width: 400,height: 300,scaleX: 1,scaleY: 1,rotation: 0,opacity: 1,borderRadius: 0,borderColor: "transparent",borderWidth: 0,shadow: {color: "rgba(0,0,0,0.5)",blur: 5,offsetX: 2,offsetY: 2}},display: {from: 2000, // Start displaying at 2 secondsto: 10000 // Stop displaying at 10 seconds}}});
Video Items
Video items display video content with playback controls and trimming capabilities.
// Add video itemdispatch("add:video", {payload: {id: "UMrEjv1EJCYbo7dB",name: "My Video",type: "video",details: {src: "https://videos.pexels.com/video-files/857251/857251-sd_540_360_25fps.mp4",width: 540,height: 360,opacity: 100,volume: 100,borderRadius: 0,borderWidth: 0,borderColor: "#000000",boxShadow: {color: "#000000",x: 0,y: 0,blur: 0},top: "780px",left: "270px",transform: "scale(2)",blur: 0,brightness: 100,flipX: false,flipY: false,rotate: "0deg",visibility: "visible"},metadata: {previewUrl: "https://images.pexels.com/videos/857251/pictures/preview-0.jpg"},trim: {from: 4651.276595744681, // Trim start in millisecondsto: 10236.3829787234 // Trim end in milliseconds},display: {from: 5794.893617021277, // Display start time in millisecondsto: 11380 // Display end time in milliseconds},duration: 13880, // Total duration in millisecondsplaybackRate: 1,isMain: false}});
Audio Items
Audio items provide audio content with volume, timing controls, and trimming capabilities.
// Add audio itemdispatch("add:audio", {payload: {id: "audio-item-id",name: "Background Music",type: "audio",details: {src: "https://example.com/audio.mp3",volume: 0.8,muted: false,loop: false,playbackRate: 1,fadeIn: 0,fadeOut: 0},trim: {from: 1000, // Trim start in millisecondsto: 9000 // Trim end in milliseconds},display: {from: 2000, // Display start time in millisecondsto: 10000 // Display end time in milliseconds},duration: 10000, // Total duration in millisecondsisMain: false}});
Shape Items
Shape items display geometric shapes and illustrations.
// Add rectangledispatch("add:rect", {payload: {name: "My Rectangle",duration: 6000, // Duration of 6 secondsdetails: {x: 100,y: 100,width: 200,height: 150,fill: "#ff0000",stroke: "#000000",strokeWidth: 2,borderRadius: 10,opacity: 1,rotation: 0},display: {from: 1000, // Start displaying at 1 secondto: 7000 // Stop displaying at 7 seconds}}});// Add circledispatch("add:circle", {payload: {name: "My Circle",duration: 4000, // Duration of 4 secondsdetails: {x: 200,y: 200,radius: 50,fill: "#00ff00",stroke: "#000000",strokeWidth: 2,opacity: 1},display: {from: 3000, // Start displaying at 3 secondsto: 7000 // Stop displaying at 7 seconds}}});
Caption Items
Caption items display timed text with word-level timing.
// Add caption itemdispatch("add:caption", {payload: {name: "My Caption",duration: 2000, // Duration of 2 secondsdetails: {text: "Hello World",fontSize: 24,fontFamily: "Arial",color: "#ffffff",backgroundColor: "rgba(0,0,0,0.8)",x: 50,y: 50,width: 300,height: 60,textAlign: "center",wordTiming: [{ word: "Hello", start: 0, end: 500 },{ word: "World", start: 500, end: 1000 }]},display: {from: 5000, // Start displaying at 5 secondsto: 7000 // Stop displaying at 7 seconds}}});
Item Properties
Display vs Trim Properties
For video and audio items (trimable elements), there are two important timing concepts:
Display Timing
The display
property controls when an item appears in the timeline:
display.from
: When the item starts displaying (in milliseconds)display.to
: When the item stops displaying (in milliseconds)
Trim Timing
The trim
property controls which portion of the media is played:
trim.from
: Start point of the media content (in milliseconds)trim.to
: End point of the media content (in milliseconds)
// Example: Video that appears at 2 seconds, plays content from 1-9 secondsconst videoItem = {trim: {from: 1000, // Play content starting at 1 secondto: 9000 // Play content until 9 seconds},display: {from: 2000, // Show in timeline starting at 2 secondsto: 8000 // Show in timeline until 8 seconds}};
Common Properties
All track items share these common properties:
interface ITrackItemBase {id: string; // Unique identifiertype: ITrackItemType; // Item typename: string; // Display nameduration: number; // Total duration in millisecondstrackId?: string; // Parent track ID (optional)details: any; // Type-specific detailsmetadata?: { // Optional metadatadescription?: string;tags?: string[];custom?: any;};animations?: IAnimation[]; // Animation datatransitions?: ITransition[]; // Transition data}// For video and audio items (trimable elements)interface ITrimableItem extends ITrackItemBase {trim: {from: number; // Trim start in millisecondsto: number; // Trim end in milliseconds};display: {from: number; // Display start time in millisecondsto: number; // Display end time in milliseconds};playbackRate: number; // Playback speed multiplierisMain: boolean; // Whether this is the main item}
Timing Properties
// Set item display timing (when item appears in timeline)dispatch("update:display", {payload: {id: "item-id",display: {from: 2000, // Display starts at 2 secondsto: 7000 // Display ends at 7 seconds}}});// Trim video/audio item (for trimable elements)dispatch("update:trim", {payload: {id: "item-id",trim: {from: 1000, // Trim 1 second from startto: 9000 // Trim 1 second from end}}});// Update item durationdispatch("update:duration", {payload: {id: "item-id",duration: 5000 // Set duration to 5 seconds}});
Position Properties
// Update item positiondispatch("update:position", {payload: {id: "item-id",x: 150,y: 200}});// Update item sizedispatch("update:size", {payload: {id: "item-id",width: 500,height: 400}});// Update item transformdispatch("update:transform", {payload: {id: "item-id",scaleX: 1.5,scaleY: 1.5,rotation: 45,opacity: 0.8}});
Item Operations
Working with Trimable Elements
Video and audio items support trimming, which allows you to control which portion of the media is played:
// Create a video with trimmingconst videoItem = {id: "video-1",name: "Trimmed Video",type: "video",details: {src: "https://example.com/video.mp4",width: 400,height: 300},trim: {from: 2000, // Start playing from 2 seconds into the videoto: 8000 // Stop playing at 8 seconds into the video},display: {from: 0, // Show in timeline from the beginningto: 6000 // Show in timeline for 6 seconds},duration: 10000, // Total video durationplaybackRate: 1,isMain: false};// Create an audio item with trimmingconst audioItem = {id: "audio-1",name: "Background Music",type: "audio",details: {src: "https://example.com/music.mp3",volume: 0.8},trim: {from: 5000, // Start playing from 5 seconds into the audioto: 15000 // Stop playing at 15 seconds into the audio},display: {from: 1000, // Start displaying at 1 second in timelineto: 11000 // Stop displaying at 11 seconds in timeline},duration: 20000, // Total audio durationplaybackRate: 1,isMain: false};
Adding Items
// Add text item with display timingdispatch("add:text", {payload: {name: "Timed Text",duration: 4000, // Duration of 4 secondsdetails: {text: "Appears at 3 seconds",fontSize: 48,color: "#ffffff"},display: {from: 3000, // Display starts at 3 secondsto: 7000 // Display ends at 7 seconds}}});// Add video item with trim and display timingdispatch("add:video", {payload: {name: "My Video",duration: 10000, // Total durationdetails: {src: "https://example.com/video.mp4",width: 400,height: 300},trim: {from: 1000, // Trim 1 second from startto: 9000 // Trim 1 second from end},display: {from: 2000, // Display starts at 2 secondsto: 8000 // Display ends at 8 seconds},playbackRate: 1,isMain: false}});// Add item to specific trackdispatch("add:image", {payload: {name: "Track Image",trackId: "track-2", // Add to specific trackduration: 10000,details: {src: "https://example.com/image.jpg",width: 400,height: 300},display: {from: 0, // Display from startto: 10000 // Display until end}}});// Add trimmed video with specific display timingdispatch("add:video", {payload: {name: "Promo Video",duration: 15000, // 15 second total durationdetails: {src: "https://example.com/promo.mp4",width: 500,height: 300},trim: {from: 3000, // Start playing from 3 seconds into videoto: 12000 // Stop playing at 12 seconds into video},display: {from: 5000, // Start showing at 5 seconds in timelineto: 14000 // Stop showing at 14 seconds in timeline},playbackRate: 1,isMain: false}});
Updating Items
// Update item detailsdispatch("update:details", {payload: {id: "item-id",details: {text: "Updated text content",fontSize: 64,color: "#ff0000"}}});// Update item namedispatch("update:name", {payload: {id: "item-id",name: "New Name"}});// Update item metadatadispatch("update:metadata", {payload: {id: "item-id",metadata: {description: "Updated description",tags: ["updated", "tag"]}}});
Removing Items
// Remove single itemdispatch("remove:item", {payload: {id: "item-id"}});// Remove multiple itemsdispatch("remove:items", {payload: {ids: ["item-1", "item-2", "item-3"]}});// Remove items by typedispatch("remove:by-type", {payload: {type: "text"}});
Duplicating Items
// Duplicate itemdispatch("duplicate:item", {payload: {id: "item-id",name: "Copy of Item" // New name}});// Duplicate multiple itemsdispatch("duplicate:items", {payload: {ids: ["item-1", "item-2"],namePrefix: "Copy of "}});
Item Selection
Selecting Items
// Select single itemdispatch("select:item", {payload: {id: "item-id"}});// Select multiple itemsdispatch("select:items", {payload: {ids: ["item-1", "item-2", "item-3"]}});// Select items by typedispatch("select:by-type", {payload: {type: "text"}});// Select all itemsdispatch("select:all");
Selection Operations
// Clear selectiondispatch("clear:selection");// Invert selectiondispatch("invert:selection");// Select next itemdispatch("select:next");// Select previous itemdispatch("select:previous");// Get selected itemsconst selectedItems = stateManager.getSelectedItems();
Item Grouping
Group Operations
// Create groupdispatch("group:items", {payload: {ids: ["item-1", "item-2", "item-3"],name: "My Group"}});// Ungroup itemsdispatch("ungroup:items", {payload: {groupId: "group-id"}});// Add item to groupdispatch("add:to-group", {payload: {itemId: "item-id",groupId: "group-id"}});// Remove item from groupdispatch("remove:from-group", {payload: {itemId: "item-id",groupId: "group-id"}});
Item Constraints
Track Constraints
// Set track acceptance rulesconst trackConfig = {id: "track-1",type: "text",accepts: ["text", "caption"], // Only accept text itemsmagnetic: true, // Snap to other tracksstatic: false // Allow movement};// Validate item placementconst isValid = timeline.validateItemPlacement(item, track);
Timing Constraints
// Set minimum durationconst minDuration = 1000; // 1 second minimum// Set maximum durationconst maxDuration = 30000; // 30 seconds maximum// Validate display timingconst isValidDisplay = timeline.validateDisplayTiming(item, {minDuration,maxDuration});// Validate trim timing (for video/audio items)const isValidTrim = timeline.validateTrimTiming(item, {minDuration,maxDuration});// Check if trim values are within media durationconst isValidTrimRange = timeline.validateTrimRange(item, {maxTrimFrom: item.duration,maxTrimTo: item.duration});
Item Rendering
Custom Rendering
// Custom text renderertimeline.setItemRenderer("text", (item, canvas, time) => {const ctx = canvas.getContext("2d");const { text, fontSize, color, x, y } = item.details;ctx.font = `${fontSize}px Arial`;ctx.fillStyle = color;ctx.fillText(text, x, y);});// Custom image renderertimeline.setItemRenderer("image", (item, canvas, time) => {const { src, x, y, width, height } = item.details;const img = new Image();img.onload = () => {const ctx = canvas.getContext("2d");ctx.drawImage(img, x, y, width, height);};img.src = src;});
Rendering Hooks
// Before render hooktimeline.onBeforeRender((item, canvas, time) => {// Pre-processing before renderingconsole.log("Rendering item:", item.name);});// After render hooktimeline.onAfterRender((item, canvas, time) => {// Post-processing after renderingconsole.log("Rendered item:", item.name);});
Item Performance
Optimization Techniques
// Enable item cachingtimeline.enableItemCaching({enabled: true,maxCacheSize: 100,cacheTimeout: 5000});// Lazy load itemstimeline.enableLazyLoading({enabled: true,threshold: 100,batchSize: 10});// Optimize renderingtimeline.setRenderOptimizations({useRequestAnimationFrame: true,debounceUpdates: true,updateInterval: 16 // 60fps});
Next Steps
- Learn about Animations
- Understand Transitions
- Explore the API Reference
- Check out Examples for practical usage