player-iframe-api-loader
The @kinescope/player-iframe-api-loader package loads the IFrame Player API without the onKinescopeIframeAPIReady callback and provides TypeScript types. Repository: kinescope/player-iframe-api-loader
.
Installation
npm install @kinescope/player-iframe-api-loader --save
Load the API
import * as iframeApiLoader from '@kinescope/player-iframe-api-loader'
const factory = await iframeApiLoader.load()
const player = await factory.create('player', {
url: 'https://kinescope.io/VIDEO_ID',
})
load() loads the API script and returns the factory. You can then use it like the standard IFrame API
: call create()
and control the player
.
Script version
The loader uses latest by default. You can specify a version or provide your own URL:
// latest (default)
await iframeApiLoader.load()
// Specific version: 'v2.123.0' or '2.123.0'
await iframeApiLoader.load('v2.123.0')
// Custom script URL
await iframeApiLoader.load(new URL('https://player.kinescope.io/latest/iframe.player.js'))
A page can use only one version of the IFrame API. If another version is already loaded,
load() throws an error.Import types only
If you load the API script yourself, you can import only the types:
import '@kinescope/player-iframe-api-loader/types'
let player: Kinescope.IframePlayer.Player | undefined
const factory = window.Kinescope?.IframePlayer
if (factory) {
player = await factory.create('player', {
url: 'https://kinescope.io/VIDEO_ID',
})
}