⚠ This lib is currently in alpha version and still in development, we are accepting feedback from the developers. ⚠
This module provides easy access to Videomatik's Player to get a preview of your video template with your customizations via the customJSON data.
Check the Support section for help.
npm i --save @videomatik/player@latest
Simple usage example rendering the player inside a div element.
import VideomatikPlayer from '@videomatik/player';
const player = new VideomatikPlayer('#videomatik-player', {
apiKey: 'WDSi8lOCua5KKzPvzx2DI86medihfQj0U8T--qSm',
templateId: 'conheca-a-italia',
compositionId: 'default',
height: 1280,
width: 720,
});
<div id="videomatik-player"></div>
First, you should get your Videomatik API Key on the Dashboard page, then you can start using this project by instantiating the main class.
const player = new VideomatikPlayer('<css selector or HTMLElement instance>', {
apiKey: '< your api key >',
templateId: '< your template id >',
compositionId: '< the selected composition id >',
});
WIP: More player options available in the future. See a preview of future options below:
const player = new VideomatikPlayer('#player', {
apiKey: 'apiKey',
templateId: 'templateId',
compositionId: 'compositionId',
customJSON: {...}, // Optional, initial customJSON when load
options: {
autoplay: true, // default
loaderColor: '#fffff',
disabledLoader: false, // default
pauseOnClick: true, // default
progressUpdateInterval: 100, // default in milliseconds
},
events: {
'onLoad' () => {},
...
}
});
If you are not familiar with the Template and CustomJSON entities for Videomatik, please check our API SDK documentation for more information. The same concept of customJSON applies to the Videomatik Player.
- templateId: Id of the Template to set
- compositionId (Optional): Id of the template composition to set. Default is
'default'
- customJSON (Optional): Initial customJSON to be passed on the first player render.
Updates the current template on the player, it will load the new template if not loaded yet.
Example:
player.setTemplate(templateId, compositionId, customJSON)
Returns the compositions available for the current video Template. Returns Array[Object]
.
Example:
player.getCompositions()
// Response Example:
[
{
compositionId: 'default',
displayName: 'Vertical',
width: 1080,
height: 1920
},
{
compositionId: 'feed',
displayName: 'Quadrado',
width: 1080,
height: 1080
}
]
- compositionId: Id of the Composition to set.
Change the composition of your template. It will load the new composition video if not loaded yet.
Example:
player.setComposition('feed')
- customJSON`: Valid customJSON object with customized parameters for the video.
Updates the custom JSON of the video.
Example:
player.setCustomJSON({
"version": "1",
"soundtrack": {...},
"images": [...],
"texts": [...],
"shapes": [...],
"colors": [...],
})
Updates the size of the video player. Only one dimension is required. The player will fit the dimension specified and keep the video aspect ratio.
Example:
player.setSize({ height: 1280, width: 720 })
This method will return the current time of the video (in seconds).
This method will return the total duration of the video (in seconds).
Play the video.
Pause the video.
- time in seconds
Sets the current time of the player. The time must be between 0 and the video duration.
Example:
player.seekTo(12.5) // Will seek to 12.5 seconds of the video
Returns the player state, which can be: 'playing'
, 'paused'
or 'loading'
.
Destroy the player and remove all event listeners.
This method will return the iframe HTML element.
There are three known errors you can receive from our API.
Error type | Occurs |
---|---|
Invalid API Key | When the player is being created. Check your Dashboard's page to get the correct API key. |
Template not found | When the player is being created or when you are setting a new template. Check your Dashboard's page to get the ID of the desired template. |
Composition not found | When the player is being created or when you are setting a new template or composition. Find valid compositions on getCompositions() method. |
When an invalid custom JSON is passed to the setCustomJson()
method or when creating the player, the Player will return the following error:
{
message: 'Invalid CustomJSON, verify CustomJSON fields.',
}
Please read the API documentation available on Videomatik's website or contact the developers through our Discord server (invite link available at our website).