Skip to main content
This guide shows you how to embed the Pictory storyboard preview player in your web application using an iframe. You’ll learn to display video previews, communicate with the player using postMessage, and update preview elements in real-time without re-rendering.

Preview Player Demo

Here’s how the embedded preview player looks when integrated into your application:

Pictory Preview Player embedded in an iframe with full playback controls

The preview player supports play/pause, seek, fullscreen controls, and responds to real-time element updates using postMessage. You can replace background visuals, modify text, and adjust settings without re-rendering the video.
Stock Visual Watermarks: The preview may display watermarked stock visuals from media libraries. These watermarks are automatically removed when you render the final video.

What You’ll Learn

Embed Preview

Display the preview player in an iframe

Player Communication

Use postMessage API to communicate with the player

Real-time Updates

Update preview elements without re-rendering

Event Handling

Handle player events like loaded and error states

Before You Begin

Make sure you have:
  • A Pictory API key (get one here)
  • A completed storyboard preview job with a previewUrl
  • Basic knowledge of JavaScript and iframe communication

Workflow Overview

The preview player integration follows a simple four-step process: create a preview, poll for completion, embed the player, and update elements in real-time.

Step 1: Create Storyboard Preview

First, create a storyboard preview using the Create Storyboard Preview API:

Step 2: Get Preview URL and Render Params

Poll the job status until it is completed to get the previewUrl and renderParams:
Example Job Response:

Background Element Structure

The backgroundElement is the core visual element for each scene. Key properties you can modify:

Step 3: Embed Preview Player in iframe

Basic HTML Implementation

Preview Editor Class

Create a preview-editor.js file with the PreviewEditor class that handles iframe communication:

Step 4: React Integration

Here’s a complete React component for embedding the preview player:

Usage in Your App

Step 5: Update Preview Elements in Real-time

The key feature is updating preview elements without re-rendering the entire video. When you modify the elements array and call updatePreview(), the player updates instantly.

Replacing Background Visual

To replace a scene’s background video or image, find the backgroundElement and update its url and visualUrl properties:

Background Element Properties

Example: Building a Background Visual Editor

Replacing Multiple Backgrounds

PostMessage API Reference

Messages Sent to the Preview Player

Messages Received from the Preview Player

Message Format

All messages follow this structure:

Complete Integration Example

Here’s a complete end-to-end example:

Best Practices

Always show a loading indicator while the preview is initializing. The player may take a few seconds to load depending on network conditions.
Always call close() when unmounting the component or navigating away to prevent memory leaks and remove event listeners.
When building live editors, debounce updates to prevent overwhelming the player with rapid changes.
Implement comprehensive error handling for network failures and player errors.

Troubleshooting

Problem: The iframe shows a blank screen or loading forever.Solutions:
  • Verify the previewUrl is valid and not expired
  • Check browser console for CORS or security errors
  • Verify your domain is allowed to embed the preview
Problem: Calling updatePreview() does not change the preview.Solutions:
  • Ensure editor.loaded is true before calling update
  • Check that elements array structure is correct
  • Verify the message is being received (check browser console)
  • Wait for the ON_LOADED event before updating
Problem: Messages are not being received by the iframe.Solutions:
  • Verify iframe.contentWindow is not null
  • Check that you are listening for messages correctly
  • Ensure the message origin matches expected sources
  • Use browser dev tools to inspect postMessage traffic
Problem: Application becomes slow after multiple preview loads.Solutions:
  • Always call editor.close() when done
  • Remove event listeners in cleanup functions
  • Clear the iframe src before removing
  • Use React’s useEffect cleanup or componentWillUnmount

Next Steps

Render Final Video

Convert the preview to a final rendered video

Render with Modifications

Apply modifications and render the final video

Create Storyboard Preview

Full API reference for preview creation

Get Storyboard Preview Job

Monitor job progress and retrieve results