If you are looking for industry leading Video Player with dual synchronous video playback, advanced layout capabilities and the power of Annoto interactivity, you are in the right place :)
Setup
The player is officially available via CDN and npm.
Annoto works out of the box with not only HTML <script> tag, but also with all major bundlers/packagers/builders, such as Browserify, WebPack, etc.
$npminstall@annoto/player
The package includes full typings and can be used in typescript/ES6/flow projects.
<body>
<script src="https://player.annoto.net/index.js"></script>
</body>
<script>
// Annoto modules is available at 'nn' global object:
// nn.annotoPlayer
</script>
Creating a Player
Annoto player is exposed as UMD module, meaning it offers compatibility with the most popular script loaders and can be imported as commonjs/amd/es6. If you are not using any standard loader the player will be exposed on window as global variables.
If you are using a javascript module loader such as RequireJS. Annoto exposes a standard UMD. For example for requireJS:
The main player class is AnnotoPlayer. After you have the player instance it can be used to load video sources, dynamically control Widget, get access to Widget API and much more.
Creating player using the annotoPlayer helper (CDN)
The annotoPlayer() helper is available only for the CDN. When using the npm package, please use the AnnotoPlayer constructor directly (see below)
import { annotoPlayer, IPlayerOptions } from '@annoto/player';
import { IConfig } from '@annoto/widget-api';
const options: IPlayerOptions;
const wConfig: Omit<IConfig, 'widgets'> = {
clientId: '...', // [mandatory for widget] the clientId provided by Annoto
ssoToken: '...', // JWT user SSO token (recomended, but can be dynamicaly authenticated using the API as well)
};
let player: AnnotoPlayer;
annotoPlayer(document.querySelector('annoto-player'), options).then((p) => {
player = p;
return Promise.all([
player.loadSrc({
src: 'https://www.youtube.com/watch?v=1T9EZi7KJcc',
type: 'video/youtube'
}),
player.setupWidget(wConfig),
]);
}).then(() => {
return player.loadWidget(); // until this api call, the widget is not shown
}).catch((err) => {
console.error('player setup error: ', err);
});
<body>
<annoto-player></annoto-player>
</body>
import {
AnnotoPlayer,
IPlayerOptions,
WidgetService,
IWidgetService,
getConsoleLogger,
} from '@annoto/player';
import { IConfig } from '@annoto/widget-api';
const options: IPlayerOptions; // optional player options
const wConfig: Omit<IConfig, 'widgets'> = {
clientId: '...', // [mandatory for widget] the clientId provided by Annoto
ssoToken: '...', // JWT user SSO token (recomended, but can be dynamicaly authenticated using the API as well)
};
// IMPORTANT: there must be only a single WidgetService on a page
// same widgetService must be used for all the players on a page
const widgetService = new WidgetService();
async function setupPlayer(el: HTMLElement, opt?: IPlayerOptions): Promise<AnnotoPlayer> {
const pl = new AnnotoPlayer(
getConsoleLogger('AnnotoPlayer'),
widgetService,
);
await pl.setup(el, opt);
return pl;
}
let player: AnnotoPlayer;
setupPlayer(document.querySelector('annoto-player'), options).then((p) => {
player = p;
return Promise.all([
player.loadSrc({
src: 'https://www.youtube.com/watch?v=1T9EZi7KJcc',
type: 'video/youtube'
}),
player.setupWidget(wConfig),
]);
}).then(() => {
return player.loadWidget(); // until this api call, the widget is not shown
}).catch((err) => {
console.error('player setup error: ', err);
});
<body>
<annoto-player></annoto-player>
</body>
const api = await player.getWidgetApi();
const ssoToken = '...';
api.auth(ssoToken);