Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ it will also import the Player constructor directly:
- [ready(): Promise<void, Error>](#ready-promisevoid-error)
- [enableTextTrack(language: string, kind?: string): Promise<object, (InvalidTrackLanguageError|InvalidTrackError|Error)>](#enabletexttracklanguage-string-kind-string-promiseobject-invalidtracklanguageerrorinvalidtrackerrorerror)
- [disableTextTrack(): Promise<void, Error>](#disabletexttrack-promisevoid-error)
- [selectAudioTrack(language: string, kind?: string): Promise<object, (NoAudioTracksError|NoAlternateAudioTracksError|NoMatchingAudioTrackError|Error)>](#selectaudiotracklanguage-string-kind-string-promiseobject-noaudiotrackserrornoalternateaudiotrackserrornomatchingaudiotrackerrorerror)
- [selectDefaultAudioTrack(): Promise<object, (NoAudioTracksError|NoAlternateAudioTracksError|NoMatchingAudioTrackError|Error)>](#selectdefaultaudiotrack-promiseobject-noaudiotrackserrornoalternateaudiotrackserrornomatchingaudiotrackerrorerror)
- [pause(): Promise<void, (PasswordError|PrivacyError|Error)>](#pause-promisevoid-passworderrorprivacyerrorerror)
- [play(): Promise<void, (PasswordError|PrivacyError|Error)>](#play-promisevoid-passworderrorprivacyerrorerror)
- [unload(): Promise<void, Error>](#unload-promisevoid-error)
Expand Down Expand Up @@ -212,6 +214,9 @@ it will also import the Player constructor directly:
- [getSeekable(): Promise<array, Error>](#getseekable-promisearray-error)
- [getSeeking(): Promise<boolean, Error>](#getseeking-promiseboolean-error)
- [getTextTracks(): Promise<object[], Error>](#gettexttracks-promiseobject-error)
- [getAudioTracks(): Promise<object[], Error>](#getaudiotracks-promiseobject-error)
- [getEnabledAudioTrack(): Promise<object[], Error>](#getenabledaudiotrack-promiseobject-error)
- [getDefaultAudioTrack(): Promise<object[], Error>](#getmainaudiotrack-promiseobject-error)
- [getVideoEmbedCode(): Promise<string, Error>](#getvideoembedcode-promisestring-error)
- [getVideoId(): Promise<number, Error>](#getvideoid-promisenumber-error)
- [getVideoTitle(): Promise<string, Error>](#getvideotitle-promisestring-error)
Expand Down Expand Up @@ -514,6 +519,74 @@ player.disableTextTrack().then(function() {
});
```

### selectAudioTrack(language: string, kind?: string): Promise<object, (NoAudioTracksError|NoAlternateAudioTracksError|NoMatchingAudioTrackError|Error)>

Enable the audio track with the specified language, and optionally the specified
kind (main, translation, descriptions, or commentary).

When set via the API, the track language will not change the viewer’s stored
preference.

```js
player.selectAudioTrack('en').then(function(track) {
// track.language = the iso code for the language. e.g. 'en' or 'en-US'.
// track.kind = the type of audio track ('main', 'translation', 'descriptions', 'commentary')
// track.label = the human-readable label
// track.provenance = string describing how the track was generated ('PROVENANCE_USER_UPLOADED', 'PROVENANCE_AI_GENERATED', 'PROVENANCE_USER_UPLOADED_AI_GENERATED')
// track.enabled = boolean reflecting whether the track is currently enabled
}).catch(function(error) {
switch (error.name) {
case 'NoAudioTracksError':
// no audio for this video
break;

case 'NoAlternateAudioTracksError':
// no alternate audio tracks to select from for this video
break;

case 'NoMatchingAudioTrackError':
// no audio track matches the options provided
break;

default:
// some other error occurred
break;
}
});
```

### selectDefaultAudioTrack(): Promise<object, (NoAudioTracksError|NoAlternateAudioTracksError|NoMatchingAudioTrackError|Error)>

Enable the default audio track for the video (the audio included with the original video upload).

```js
player.selectDefaultAudioTrack().then(function(track) {
// track.language = the iso code for the language. e.g. 'en' or 'en-US'.
// track.kind = the type of audio track ('main', 'translation', 'descriptions', 'commentary')
// track.label = the human-readable label
// track.provenance = string describing how the track was generated ('PROVENANCE_USER_UPLOADED', 'PROVENANCE_AI_GENERATED', 'PROVENANCE_USER_UPLOADED_AI_GENERATED')
// track.enabled = boolean reflecting whether the track is currently enabled
}).catch(function(error) {
switch (error.name) {
case 'NoAudioTracksError':
// no audio for this video
break;

case 'NoAlternateAudioTracksError':
// no alternate audio tracks to select from for this video
break;

case 'NoMatchingAudioTrackError':
// no audio track matches the options provided
break;

default:
// some other error occurred
break;
}
});
```

### pause(): Promise<void, (PasswordError|PrivacyError|Error)>

Pause the video if it’s playing.
Expand Down Expand Up @@ -1191,6 +1264,84 @@ Kind can be either `captions` or `subtitles`. The mode can be either `showing`
or `disabled`. Only one track can be `showing` at any given time; the rest will
be `disabled`.

### getAudioTracks(): Promise<object[], Error>

Get an array of the audio tracks that exist for the video. For example:

```js
player.getAudioTracks().then(function(tracks) {
// tracks = an array of track objects
}).catch(function(error) {
// an error occurred
});
```

Each track object looks like this:

```js
{
"label": "English",
"language": "en",
"kind": "main",
"provenance": "PROVENANCE_USER_UPLOADED",
"enabled": true,
}
```

Language will follow the ISO standard of either a language code or language-locale code (e.g. "en" or "en-US"). Kind can be any of the following: "main", "translation", "descriptions", or "commentary". Provenance can be any of the following: "PROVENANCE_USER_UPLOADED", "PROVENANCE_AI_GENERATED", "PROVENANCE_USER_UPLOADED_AI_GENERATED".

### getEnabledAudioTrack(): Promise<object, Error>

Get the currently enabled audio track for the video. For example:

```js
player.getEnabledAudioTrack().then(function(track) {
// track = track object
}).catch(function(error) {
// an error occurred
});
```

The track object looks like this:

```js
{
"label": "English",
"language": "en",
"kind": "main",
"provenance": "PROVENANCE_USER_UPLOADED",
"enabled": true,
}
```

Kind can be any of the following: "main", "translation", "descriptions", or "commentary".

### getDefaultAudioTrack(): Promise<object, Error>

Get the main audio track for the video (the one included with the video on upload). For example:

```js
player.getDefaultAudioTrack().then(function(track) {
// track = track object
}).catch(function(error) {
// an error occurred
});
```

The track object looks like this:

```js
{
"label": "English",
"language": "en",
"kind": "main",
"provenance": "PROVENANCE_USER_UPLOADED",
"enabled": true,
}
```

Kind can be any of the following: "main", "translation", "descriptions", or "commentary".

### getVideoEmbedCode(): Promise<string, Error>

Get the `<iframe>` embed code for the video.
Expand Down
94 changes: 93 additions & 1 deletion dist/player.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ var npo_src = createCommonjsModule(function (module) {
(function UMD(name, context, definition) {
// special form of UMD for polyfilling across evironments
context[name] = context[name] || definition();
if (module.exports) {
if ( module.exports) {
module.exports = context[name];
}
})("Promise", typeof commonjsGlobal != "undefined" ? commonjsGlobal : commonjsGlobal, function DEF() {
Expand Down Expand Up @@ -2630,6 +2630,53 @@ var Player = /*#__PURE__*/function () {
return this.callMethod('disableTextTrack');
}

/** @typedef {import('../types/formats.js').VimeoAudioTrack} VimeoAudioTrack */
/** @typedef {import('../types/formats.js').AudioLanguage} AudioLanguage */
/** @typedef {import('../types/formats.js').AudioKind} AudioKind */
/**
* A promise to enable an audio track.
*
* @promise SelectAudioTrackPromise
* @fulfill {VimeoAudioTrack} The audio track that was enabled.
* @reject {NoAudioTracksError} No audio exists for the video.
* @reject {NoAlternateAudioTracksError} No alternate audio tracks exist for the video.
* @reject {NoMatchingAudioTrackError} No track was available with the specified
* language and kind.
*/
/**
* Enable the audio track with the specified language, and optionally the
* specified kind (main, translation, descriptions, or commentary).
*
* When set via the API, the track language will not change the viewer’s
* stored preference.
*
* @param {AudioLanguage} language The two‐letter language code.
* @param {AudioKind} [kind] The kind of track to enable (main, translation, descriptions, commentary).
* @return {SelectAudioTrackPromise}
*/
}, {
key: "selectAudioTrack",
value: function selectAudioTrack(language, kind) {
if (!language) {
throw new TypeError('You must pass a language.');
}
return this.callMethod('selectAudioTrack', {
language: language,
kind: kind
});
}

/**
* Enable the main audio track for the video.
*
* @return {SelectAudioTrackPromise}
*/
}, {
key: "selectDefaultAudioTrack",
value: function selectDefaultAudioTrack() {
return this.callMethod('selectDefaultAudioTrack');
}

/**
* A promise to pause the video.
*
Expand Down Expand Up @@ -3454,6 +3501,51 @@ var Player = /*#__PURE__*/function () {
return this.get('textTracks');
}

/**
* A promise to get the audio tracks of a video.
*
* @promise GetAudioTracksPromise
* @fulfill {VimeoAudioTrack[]} The audio tracks associated with the video.
*/
/**
* Get an array of the audio tracks that exist for the video.
*
* @return {GetAudioTracksPromise}
*/
}, {
key: "getAudioTracks",
value: function getAudioTracks() {
return this.get('audioTracks');
}

/**
* A promise to get the enabled audio track of a video.
*
* @promise GetAudioTrackPromise
* @fulfill {VimeoAudioTrack} The enabled audio track.
*/
/**
* Get the enabled audio track for a video.
*
* @return {GetAudioTrackPromise}
*/
}, {
key: "getEnabledAudioTrack",
value: function getEnabledAudioTrack() {
return this.get('enabledAudioTrack');
}

/**
* Get the main audio track for a video.
*
* @return {GetAudioTrackPromise}
*/
}, {
key: "getDefaultAudioTrack",
value: function getDefaultAudioTrack() {
return this.get('defaultAudioTrack');
}

/**
* A promise to get the embed code for the video.
*
Expand Down
Loading