Skip to content

Commit

Permalink
Merge pull request #27 from apivideo/subtitle-methods
Browse files Browse the repository at this point in the history
Add showSubtitles() / hideSubtitles() methods
  • Loading branch information
olivier-lando authored Jul 7, 2021
2 parents f61b40d + 10b3ff3 commit 3f7c39b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [1.2.8] - 2021-05-28
- Add showSubtitles() / hideSubtitles() methods

## [1.2.7] - 2021-05-28
- Add "token" in SdkOptions type

Expand Down
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ The PlayerSdk constructor takes 2 parameters:
- `options: SdkOptions` an object containing the player options. The available options are the following:


| Option name | Mandatory | Type | Description |
| -----------: | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| id | **yes** | string | the id of the video |
| token | yes for private video | string | the [private video](https://api.video/blog/tutorials/tutorial-private-videos) url token |
| live | no (default: false) | boolean | indicate that the video is a live one |
| autoplay | no (default: false) | boolean | start playing the video as soon as it is loaded |
| muted | no (default: false) | boolean | the video is muted |
| metadata | no (default: empty) | object | object containing [metadata](https://api.video/blog/tutorials/dynamic-metadata) (see **Full example** below) |
| hideControls | no (default: false) | boolean | the controls are hidden |
| hideTitle | no (default: false) | boolean | the video title is hidden |
| loop | no (default: false) | boolean | once the video is finished it automatically starts again |
| Option name | Mandatory | Type | Description |
| ------------: | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| id | **yes** | string | the id of the video |
| token | yes for private video | string | the [private video](https://api.video/blog/tutorials/tutorial-private-videos) url token |
| live | no (default: false) | boolean | indicate that the video is a live one |
| autoplay | no (default: false) | boolean | start playing the video as soon as it is loaded |
| muted | no (default: false) | boolean | the video is muted |
| metadata | no (default: empty) | object | object containing [metadata](https://api.video/blog/tutorials/dynamic-metadata) (see **Full example** below) |
| hideControls | no (default: false) | boolean | the controls are hidden |
| hideTitle | no (default: false) | boolean | the video title is hidden |
| showSubtitles | no (default: false) | boolean | the video subtitles are shown by default |
| loop | no (default: false) | boolean | once the video is finished it automatically starts again |


The sdk instance can be used to control the video playback, and to listen to player events.
Expand Down Expand Up @@ -115,6 +116,10 @@ The sdk instance has the following methods:
> Hide the player controls.
#### `showControls()`
> Show the player controls.
#### `hideSubtitles()`
> Hide the player subtitles.
#### `showSubtitles()`
> Show the player subtitles.
#### `setLoop(loop: boolean)`
> Define if the video should be played in loop.
#### `seek(time: number)`
Expand Down
3 changes: 3 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare type SdkOptions = {
hideTitle?: boolean;
iframeUrl?: string;
token?: string;
showSubtitles?: boolean;
};
export declare class PlayerSdk {
private static DEFAULT_IFRAME_URL;
Expand All @@ -29,6 +30,8 @@ export declare class PlayerSdk {
play(): void;
hideControls(): void;
showControls(): void;
hideSubtitles(): void;
showSubtitles(): void;
pause(): void;
mute(): void;
unmute(): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SdkOptions = {
hideTitle?: boolean;
iframeUrl?: string;
token?: string;
showSubtitles?: boolean;
}

export class PlayerSdk {
Expand Down Expand Up @@ -93,6 +94,12 @@ export class PlayerSdk {
showControls() {
this.postMessage({ message: 'showControls' });
}
hideSubtitles() {
this.postMessage({ message: 'hideSubtitles' });
}
showSubtitles() {
this.postMessage({ message: 'showSubtitles' });
}
pause() {
this.postMessage({ message: 'pause' });
}
Expand Down Expand Up @@ -200,6 +207,10 @@ export class PlayerSdk {
url = addParameterInIframeHash("hide-title");
}

if (options.showSubtitles === true) {
url = addParameterInIframeHash("show-subtitles");
}

return url;
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@api.video/player-sdk",
"version": "1.2.7",
"version": "1.2.8",
"description": "api.video player SDK",
"repository": {
"type": "git",
Expand Down

0 comments on commit 3f7c39b

Please sign in to comment.