- 15 Oct 2024
- 1 Minute to read
- Print
Player API Flow
- Updated on 15 Oct 2024
- 1 Minute to read
- Print
Player API Flow
The Player API defines the flow of control between the player and the template, and allows for seamless orchestration of content. In order to achieve gapless and glitchfree switches between content, the API allows the template to preload its content in the background, while the previous content is still playing.
When developing a template, one can choose to implement the Player API directly. However, in most cases it will be easier to use the TypeScript Framework provided in this SDK. Still, an understanding of the Player API flow is vital.
As illustrated above, the event flow of the API works in the following way:
- The player starts to load the template and calls the "onLoad" function in the API. This function is the equivalent of the window.onload event and will be run when the template has been completely loaded. Here the template can initialize everything it needs that isn't dynamic content.
- When the template is done loading all it needs, it calls the function cmdReady, which tells the player that the template is ready to receive data.
- The player now sends in the JSON data to the template by running the onPreload function. The data object is already parsed at this point so no need to decode the JSON. The template can now load all its dynamic content from the data it has received, i.e., external images, texts, set up animations that need dynamic settings etc.
- When everything in the template is prepared and ready to be viewed, the template calls the preloadComplete function, letting the player know that the template is ready to be displayed.
- When the current item in the playlist is done playing, the player switches the template to be displayed and lets the template know by calling the onShift function. This is usually when the template starts videos and animations.
- When all animations in the template are done it can, optionally, call the function templateEnded to let the player know that it has finished displaying all it wanted to display and let the player know it can skip to the next media in the playlist.
API functions
When implementing a template using the API, as opposed to using the Framework, the JavaScript module "XXX.js" should be included. The file contains documentation and examples.