Video player API for JavaScript

Control the Kinescope player embedded on your page: play, seek, change speed and quality, switch subtitles and playlists, and react to what the viewer does.

Control the player from your code

A real Kinescope player. Each button calls an IFrame Player API method, the panel shows the code that ran, and the log shows the events the player sends back.

Live player Loads as you scroll here
currentTime
0
paused
true
playbackRate
1
quality
—
volume
1
muted
false
Playback
Seek result Try seekTo(90) to jump to 1:30.
Speed
Quality
Sound
Subtitles
// Try seekTo(90) in the live player
Events
  1. Events appear here once the player loads.
player.js
import { load } from '@kinescope/player-iframe-api-loader';

const factory = await load();
const player = await factory.create('player', {
  url: 'https://kinescope.io/56Jg27MqvvttAwHcrCzEA4',
  size: { width: '100%', height: '100%' },
});

player.on(player.Events.TimeUpdate, ({ data }) => {
  console.log(data.currentTime, data.percent);
});

Every method and event is in the IFrame Player API docs.

Quick start

Install @kinescope/player-iframe-api-loader and control your first video. Code from the package README and the API types.
terminal
npm install @kinescope/player-iframe-api-loader
added 1 package in 1s
player.ts
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',
  size: { width: '100%', height: 400 },
});
player.ts
player.on(player.Events.Ended, () => {
  console.log('Lesson finished');
});

await player.seekTo(90);
await player.setPlaybackRate(1.5);
await player.play();
Install the loader
The loader fetches the IFrame API and ships TypeScript types for every method and event.
terminal
npm install @kinescope/player-iframe-api-loader
added 1 package in 1s
Create the player
Pass an element or its ID and the video link. size and behavior are optional.
player.ts
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',
  size: { width: '100%', height: 400 },
});
Call methods and listen to events
Every method returns a Promise. Subscribe with on, once and off.
player.ts
player.on(player.Events.Ended, () => {
  console.log('Lesson finished');
});

await player.seekTo(90);
await player.setPlaybackRate(1.5);
await player.play();

Methods you’ll use most

Every method returns a Promise. All 33 methods in the API docs.

  • play() · pause()Promise

    Start or pause playback.

  • seekTo(time)Promise

    Jump to a second, for example to resume a lesson.

  • getCurrentTime()Promise<number>

    Where the viewer is now, in seconds.

  • getDuration()Promise<number>

    Length of the video, in seconds.

  • setPlaybackRate(value)Promise

    Change speed, for example 1.5.

  • setVideoQuality(q)Promise

    Fix a quality, such as 720p.

  • enableTextTrack(lang)Promise

    Turn on subtitles in a language.

  • setFullscreen(on)Promise

    Enter or leave fullscreen.

  • switchTo(id) · next()Promise

    Change the video in a playlist.

  • setOptions(options)Promise

    Change player options on the fly, such as the watermark.

Events

  • LoadedCall methods safely after it.

    The player and video are ready.

  • Play · PauseSync your own buttons.

    The viewer starts or pauses.

  • TimeUpdateSave lesson progress.

    Playback position changes.

  • EndedMark a lesson as watched, open the next one.

    The video reaches the end.

  • QualityChangedLog what viewers actually get.

    The quality switches.

  • CallActionCount clicks or open a form.

    A viewer clicks a call to action.

  • ErrorShow your own message or report it.

    Playback fails.

  • player.on(Events.Ended, fn)Also once and off.

    Subscribe to any event.

FAQ

Can’t find the answer you need? Check out our Player docs.

A JavaScript API for a video player embedded in an iframe: your page calls methods such as play, seek or change quality, and the player sends back events such as playing, paused or ended. It is how you build custom controls, lesson progress tracking or interactive video on top of an embedded player.

Install @kinescope/player-iframe-api-loader, call load() to get the player factory, create the player with factory.create(element, { url }), then call its methods and subscribe to events with player.on(player.Events.Ended, handler). The quick start on this page has the code.

Yes. Listen to Ended for the end of the video and to TimeUpdate for the current position, then save progress on your backend. getCurrentTime() and getDuration() return the values on demand.

No. The loader replaces the onKinescopeIframeAPIReady callback and adds TypeScript types. If the IFrame API script is already on the page, use window.Kinescope.IframePlayer directly; the types are available on their own from @kinescope/player-iframe-api-loader/types.