UNPKG

38.9 kBMarkdownView Raw
1# Vimeo Player API [![Build Status](https://travis-ci.org/vimeo/player.js.svg?branch=master)](https://travis-ci.org/vimeo/player.js) [![Coverage](https://img.shields.io/codecov/c/github/vimeo/player.js.svg?maxAge=2592000)](https://codecov.io/gh/vimeo/player.js) [![npm](https://img.shields.io/npm/v/@vimeo/player.svg?maxAge=2592000)](https://www.npmjs.com/package/@vimeo/player)
2
3The Vimeo Player API allows you to interact with and control an embedded Vimeo
4Player.
5
6## Installation
7
8You can install the Vimeo Player API through either npm:
9
10```bash
11npm install @vimeo/player
12```
13
14Alternatively, you can reference an up‐to‐date version on our CDN:
15
16```html
17<script src="https://player.vimeo.com/api/player.js"></script>
18```
19
20**Warning:** when used with RequireJS it's required to load the script dynamically via the RequireJS load system.
21http://www.requirejs.org/docs/api.html#jsfiles
22
23## Getting Started
24
25In order to control the Vimeo player, you need a player to control. There are a
26few ways to get a player:
27
28### Pre-existing player
29
30Already have a player on the page? Pass the element to the `Vimeo.Player`
31constructor and you’re ready to go.
32
33```html
34<iframe src="https://player.vimeo.com/video/76979871" width="640" height="360" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
35
36<script src="https://player.vimeo.com/api/player.js"></script>
37<script>
38 var iframe = document.querySelector('iframe');
39 var player = new Vimeo.Player(iframe);
40
41 player.on('play', function() {
42 console.log('played the video!');
43 });
44
45 player.getVideoTitle().then(function(title) {
46 console.log('title:', title);
47 });
48</script>
49```
50
51### Create with a video id or url
52
53You can use the library to make the embed for you. All you need is an empty
54element and the video id or vimeo.com url (and optional
55[embed options](#embed-options)).
56
57```html
58<div id="made-in-ny"></div>
59
60<script src="https://player.vimeo.com/api/player.js"></script>
61<script>
62 var options = {
63 id: 59777392,
64 width: 640,
65 loop: true
66 };
67
68 var player = new Vimeo.Player('made-in-ny', options);
69
70 player.setVolume(0);
71
72 player.on('play', function() {
73 console.log('played the video!');
74 });
75</script>
76```
77
78### Automatically with HTML attributes
79
80When the library loads, it will scan your page for elements with Vimeo
81attributes. Each element must have at least a `data-vimeo-id` or
82`data-vimeo-url` attribute in order for the embed to be created automatically.
83You can also add attributes for any of the [embed options](#embed-options),
84prefixed with `data-vimeo` (`data-vimeo-portrait="false"`, for example).
85
86```html
87<div data-vimeo-id="19231868" data-vimeo-width="640" id="handstick"></div>
88<div data-vimeo-url="https://vimeo.com/76979871" id="playertwo"></div>
89
90<script src="https://player.vimeo.com/api/player.js"></script>
91<script>
92 // If you want to control the embeds, you’ll need to create a Player object.
93 // You can pass either the `<div>` or the `<iframe>` created inside the div.
94 var handstickPlayer = new Vimeo.Player('handstick');
95 handstickPlayer.on('play', function() {
96 console.log('played the handstick video!');
97 });
98
99 var playerTwoPlayer = new Vimeo.Player('playertwo');
100 playerTwoPlayer.on('play', function() {
101 console.log('played the player 2.0 video!');
102 });
103</script>
104```
105
106## Browser Support
107
108The Player API library is supported in IE 11+, Chrome, Firefox, Safari, and
109Opera.
110
111## Migrate from Froogaloop
112
113Using our old Froogaloop library? See the [migration doc](docs/migrate-from-froogaloop.md)
114for details on how to update your code to use this library.
115
116## Using with a module bundler
117
118If you’re using a module bundler like [webpack](https://webpack.js.org) or
119[rollup](http://rollupjs.org/), the exported object will be the Player
120constructor (unlike the browser where it is attached to `window.Vimeo`):
121
122```js
123import Player from '@vimeo/player';
124
125const player = new Player('handstick', {
126 id: 19231868,
127 width: 640
128});
129
130player.on('play', function() {
131 console.log('played the video!');
132});
133```
134
135Similarly, if you’re using [RequireJS](http://www.requirejs.org) in the browser,
136it will also import the Player constructor directly:
137
138```html
139<iframe src="https://player.vimeo.com/video/76979871" width="640" height="360" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
140
141<script>
142 require(['https://player.vimeo.com/api/player.js'], function (Player) {
143 var iframe = document.querySelector('iframe');
144 var player = new Player(iframe);
145
146 player.on('play', function() {
147 console.log('played the video!');
148 });
149 });
150</script>
151```
152
153## Table of Contents
154
155* [Create a Player](#create-a-player)
156* [Methods](#methods)
157 + [on](#onevent-string-callback-function-void)
158 + [off](#offevent-string-callback-function-void)
159 + [loadVideo](#loadvideooptions-numberobject-promisenumberobject-typeerrorpassworderrorerror)
160 + [ready](#ready-promisevoid-error)
161 + [enableTextTrack](#enabletexttracklanguage-string-kind-string-promiseobject-invalidtracklanguageerrorinvalidtrackerrorerror)
162 + [disableTextTrack](#disabletexttrack-promisevoid-error)
163 + [pause](#pause-promisevoid-passworderrorprivacyerrorerror)
164 + [play](#play-promisevoid-passworderrorprivacyerrorerror)
165 + [unload](#unload-promisevoid-error)
166 + [destroy](#destroy-promisevoid-error)
167 + [getAutopause](#getautopause-promiseboolean-unsupportederrorerror)
168 + [setAutopause](#setautopauseautopause-boolean-promiseboolean-unsupportederrorerror)
169 + [getBuffered](#getbuffered-promisearray-error)
170 + [getColor](#getcolor-promisestring-error)
171 + [setColor](#setcolorcolor-string-promisestring-contrasterrortypeerrorerror)
172 + [addCuePoint](#addcuepointtime-number-data-object-promisestring-unsupportederrorrangeerrorerror)
173 + [removeCuePoint](#removecuepointid-string-promisestring-unsupportederrorinvalidcuepointerror)
174 + [getCuePoints](#getcuepoints-promisearray-unsupportederrorerror)
175 + [getCurrentTime](#getcurrenttime-promisenumber-error)
176 + [setCurrentTime](#setcurrenttimeseconds-number-promisenumber-rangeerrorerror)
177 + [getDuration](#getduration-promisenumber-error)
178 + [getEnded](#getended-promiseboolean-error)
179 + [getLoop](#getloop-promiseboolean-error)
180 + [setLoop](#setlooploop-boolean-promiseboolean-error)
181 + [getMuted](#getmuted-promiseboolean-error)
182 + [setMuted](#setmuted-boolean-promiseboolean-error)
183 + [getPaused](#getpaused-promiseboolean-error)
184 + [getPlaybackRate](#getplaybackrate-promisenumber-error)
185 + [setPlaybackRate](#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror)
186 + [getPlayed](#getplayed-promisearray-error)
187 + [getSeekable](#getseekable-promisearray-error)
188 + [getSeeking](#getseeking-promiseboolean-error)
189 + [getTextTracks](#gettexttracks-promiseobject-error)
190 + [getVideoEmbedCode](#getvideoembedcode-promisestring-error)
191 + [getVideoId](#getvideoid-promisenumber-error)
192 + [getVideoTitle](#getvideotitle-promisestring-error)
193 + [getVideoWidth](#getvideowidth-promisenumber-error)
194 + [getVideoHeight](#getvideoheight-promisenumber-error)
195 + [getVideoUrl](#getvideourl-promisestring-privacyerrorerror)
196 + [getVolume](#getvolume-promisenumber-error)
197 + [setVolume](#setvolumevolume-number-promisenumber-rangeerrorerror)
198* [Events](#events)
199 + [play](#play)
200 + [pause](#pause)
201 + [ended](#ended)
202 + [timeupdate](#timeupdate)
203 + [progress](#progress)
204 + [seeking](#seeking)
205 + [seeked](#seeked)
206 + [texttrackchange](#texttrackchange)
207 + [cuechange](#cuechange)
208 + [cuepoint](#cuepoint)
209 + [volumechange](#volumechange)
210 + [playbackratechange](#playbackratechange)
211 + [bufferstart](#bufferstart)
212 + [bufferend](#bufferend)
213 + [error](#error)
214 + [loaded](#loaded)
215* [Embed Options](#embed-options)
216
217## Create a Player
218
219The `Vimeo.Player` object wraps an iframe so you can interact with and control a
220Vimeo Player embed.
221
222### Existing embed
223
224If you already have a Vimeo `<iframe>` on your page, pass that element into the
225constructor to get a `Player` object. You can also use jQuery to select the
226element, or pass a string that matches the `id` of the `<iframe>`.
227
228```js
229// Select with the DOM API
230var iframe = document.querySelector('iframe');
231var iframePlayer = new Vimeo.Player(iframe);
232
233// Select with jQuery
234// If multiple elements are selected, it will use the first element.
235var jqueryPlayer = new Vimeo.Player($('iframe'));
236
237// Select with the `<iframe>`’s id
238// Assumes that there is an <iframe id="player1"> on the page.
239var idPlayer = new Vimeo.Player('player1');
240```
241
242### Create an embed
243
244Pass any element and an options object to the `Vimeo.Player` constructor to make
245an embed inside that element. The options object should consist of either an
246`id` or `url` and any other [embed options](#embed-options) for the embed.
247
248```html
249<div id="made-in-ny"></div>
250
251<script src="https://player.vimeo.com/api/player.js"></script>
252<script>
253 var options = {
254 id: 59777392,
255 width: 640,
256 loop: true
257 };
258
259 // Will create inside the made-in-ny div:
260 // <iframe src="https://player.vimeo.com/video/59777392?loop=1" width="640" height="360" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
261 var madeInNy = new Vimeo.Player('made-in-ny', options);
262</script>
263```
264
265Embed options will also be read from the `data-vimeo-*` attributes. Attributes
266on the element will override any defined in the options object passed to the
267constructor (similar to how the `style` attribute overrides styles defined in
268CSS).
269
270Elements with a `data-vimeo-id` or `data-vimeo-url` attribute will have embeds
271created automatically when the player API library is loaded. You can use the
272`data-vimeo-defer` attribute to prevent that from happening and create the embed
273at a later time. This is useful for situations where the player embed wouldn’t
274be visible right away, but only after some action was taken by the user (a
275lightbox opened from clicking on a thumbnail, for example).
276
277```html
278<div data-vimeo-id="59777392" data-vimeo-defer id="made-in-ny"></div>
279<div data-vimeo-id="19231868" data-vimeo-defer data-vimeo-width="500" id="handstick"></div>
280
281<script src="https://player.vimeo.com/api/player.js"></script>
282<script>
283 var options = {
284 width: 640,
285 loop: true
286 };
287
288 // Will create inside the made-in-ny div:
289 // <iframe src="https://player.vimeo.com/video/59777392?loop=1" width="640" height="360" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
290 var madeInNy = new Vimeo.Player('made-in-ny', options);
291
292 // Will create inside the handstick div:
293 // <iframe src="https://player.vimeo.com/video/19231868?loop=1" width="500" height="281" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>
294 var handstick = new Vimeo.Player(document.getElementById('handstick'), options);
295</script>
296```
297
298## Methods
299
300You can call methods on the player by calling the function on the Player object:
301
302```js
303player.play();
304```
305
306All methods, except for `on()` and `off()` return a
307[Promise](http://www.html5rocks.com/en/tutorials/es6/promises/). The Promise may
308or may not resolve with a value, depending on the specific method.
309
310```js
311player.disableTextTrack().then(function() {
312 // the track was disabled
313}).catch(function(error) {
314 // an error occurred
315});
316```
317
318Promises for getters are resolved with the value of the property:
319
320```js
321player.getLoop().then(function(loop) {
322 // whether or not the player is set to loop
323});
324```
325
326Promises for setters are resolved with the value set, or rejected with an error
327if the set fails. For example:
328
329```js
330player.setColor('#00adef').then(function(color) {
331 // the color that was set
332}).catch(function(error) {
333 // an error occurred setting the color
334});
335```
336
337### on(event: string, callback: function): void
338
339Add an event listener for the specified event. Will call the callback with a
340single parameter, `data`, that contains the data for that event. See
341[events](#events) below for details.
342
343```js
344var onPlay = function(data) {
345 // data is an object containing properties specific to that event
346};
347
348player.on('play', onPlay);
349```
350
351### off(event: string, callback?: function): void
352
353Remove an event listener for the specified event. Will remove all listeners for
354that event if a `callback` isn’t passed, or only that specific callback if it is
355passed.
356
357```js
358var onPlay = function(data) {
359 // data is an object containing properties specific to that event
360};
361
362player.on('play', onPlay);
363
364// If later on you decide that you don’t need to listen for play anymore.
365player.off('play', onPlay);
366
367// Alternatively, `off` can be called with just the event name to remove all
368// listeners.
369player.off('play');
370```
371
372### loadVideo(options: number|object): Promise&lt;number|object, (TypeError|PasswordError|Error)&gt;
373
374Load a new video into this embed. The promise will be resolved if the video is
375successfully loaded, or it will be rejected if it could not be loaded.
376
377```js
378player.loadVideo(76979871).then(function(id) {
379 // the video successfully loaded
380}).catch(function(error) {
381 switch (error.name) {
382 case 'TypeError':
383 // the id was not a number
384 break;
385
386 case 'PasswordError':
387 // the video is password-protected and the viewer needs to enter the
388 // password first
389 break;
390
391 case 'PrivacyError':
392 // the video is password-protected or private
393 break;
394
395 default:
396 // some other error occurred
397 break;
398 }
399});
400```
401
402### ready(): Promise&lt;void, Error&gt;
403
404Trigger a function when the player iframe has initialized. You do not need to
405wait for `ready` to trigger to begin adding event listeners or calling other
406methods.
407
408```js
409player.ready().then(function() {
410 // the player is ready
411});
412```
413
414### enableTextTrack(language: string, kind?: string): Promise&lt;object, (InvalidTrackLanguageError|InvalidTrackError|Error)&gt;
415
416Enable the text track with the specified language, and optionally the specified
417kind (captions or subtitles).
418
419When set via the API, the track language will not change the viewer’s stored
420preference.
421
422```js
423player.enableTextTrack('en').then(function(track) {
424 // track.language = the iso code for the language
425 // track.kind = 'captions' or 'subtitles'
426 // track.label = the human-readable label
427}).catch(function(error) {
428 switch (error.name) {
429 case 'InvalidTrackLanguageError':
430 // no track was available with the specified language
431 break;
432
433 case 'InvalidTrackError':
434 // no track was available with the specified language and kind
435 break;
436
437 default:
438 // some other error occurred
439 break;
440 }
441});
442```
443
444### disableTextTrack(): Promise&lt;void, Error&gt;
445
446Disable the currently-active text track.
447
448```js
449player.disableTextTrack().then(function() {
450 // the track was disabled
451}).catch(function(error) {
452 // an error occurred
453});
454```
455
456### pause(): Promise&lt;void, (PasswordError|PrivacyError|Error)&gt;
457
458Pause the video if it’s playing.
459
460```js
461player.pause().then(function() {
462 // the video was paused
463}).catch(function(error) {
464 switch (error.name) {
465 case 'PasswordError':
466 // the video is password-protected and the viewer needs to enter the
467 // password first
468 break;
469
470 case 'PrivacyError':
471 // the video is private
472 break;
473
474 default:
475 // some other error occurred
476 break;
477 }
478});
479```
480
481### play(): Promise&lt;void, (PasswordError|PrivacyError|Error)&gt;
482
483Play the video if it’s paused. **Note:** on iOS and some other mobile devices,
484you cannot programmatically trigger play. Once the viewer has tapped on the play
485button in the player, however, you will be able to use this function.
486
487```js
488player.play().then(function() {
489 // the video was played
490}).catch(function(error) {
491 switch (error.name) {
492 case 'PasswordError':
493 // the video is password-protected and the viewer needs to enter the
494 // password first
495 break;
496
497 case 'PrivacyError':
498 // the video is private
499 break;
500
501 default:
502 // some other error occurred
503 break;
504 }
505});
506```
507
508### unload(): Promise&lt;void, Error&gt;
509
510Return the internal player (iframe) to its initial state.
511
512```js
513player.unload().then(function() {
514 // the video was unloaded
515}).catch(function(error) {
516 // an error occurred
517});
518```
519### destroy(): Promise&lt;void, Error&gt;
520
521Cleanup the player and remove it from the DOM.
522
523It won't be usable and a new one should be constructed
524 in order to do any operations.
525
526```js
527player.destroy().then(function() {
528 // the player was destroyed
529}).catch(function(error) {
530 // an error occurred
531});
532```
533
534### getAutopause(): Promise&lt;boolean, (UnsupportedError|Error)&gt;
535
536Get the autopause behavior for this player.
537
538```js
539player.getAutopause().then(function(autopause) {
540 // autopause = whether autopause is turned on or off
541}).catch(function(error) {
542 switch (error.name) {
543 case 'UnsupportedError':
544 // Autopause is not supported with the current player or browser
545 break;
546
547 default:
548 // some other error occurred
549 break;
550 }
551});
552```
553
554### setAutopause(autopause: boolean): Promise&lt;boolean, (UnsupportedError|Error)&gt;
555
556Enable or disable the autopause behavior of this player. By default, when
557another video is played in the same browser, this player will automatically
558pause. Unless you have a specific reason for doing so, we recommend that you
559leave autopause set to the default (`true`).
560
561```js
562player.setAutopause(false).then(function(autopause) {
563 // autopause was turned off
564}).catch(function(error) {
565 switch (error.name) {
566 case 'UnsupportedError':
567 // Autopause is not supported with the current player or browser
568 break;
569
570 default:
571 // some other error occurred
572 break;
573 }
574});
575```
576
577### getBuffered(): Promise&lt;array, Error&gt;
578
579Get the buffered time ranges of the video.
580
581```js
582player.getBuffered().then(function(buffered) {
583 // buffered = an array of the buffered video time ranges.
584}).catch(function(error) {
585 // an error occurred
586});
587```
588
589### getColor(): Promise&lt;string, Error&gt;
590
591Get the color for this player.
592
593```js
594player.getColor().then(function(color) {
595 // color = the hex color of the player
596}).catch(function(error) {
597 // an error occurred
598});
599```
600
601### setColor(color: string): Promise&lt;string, (ContrastError|TypeError|Error)&gt;
602
603Set the color of this player to a hex or rgb string. Setting the color may fail
604if the owner of the video has set their embed preferences to force a specific
605color.
606
607```js
608player.setColor('#00adef').then(function(color) {
609 // color was successfully set
610}).catch(function(error) {
611 switch (error.name) {
612 case 'ContrastError':
613 // the color was set, but the contrast is outside of the acceptable
614 // range
615 break;
616
617 case 'TypeError':
618 // the string was not a valid hex or rgb color
619 break;
620
621 case 'EmbedSettingsError':
622 // the owner of the video has chosen to use a specific color
623 break;
624
625 default:
626 // some other error occurred
627 break;
628 }
629});
630```
631
632### addCuePoint(time: number, data: object): Promise&lt;string, (UnsupportedError|RangeError|Error)&gt;
633
634Add a cue point to the player. Cue points fire a `cuepoint` event when the
635`currentTime` of the video passes the specified time. *Note:* cue points should
636be accurate to within a tenth of a second, but the precision may vary based on
637browser or environment.
638
639```js
640player.addCuePoint(15, {
641 customKey: 'customValue'
642}).then(function(id) {
643 // cue point was added successfully
644}).catch(function(error) {
645 switch (error.name) {
646 case 'UnsupportedError':
647 // cue points are not supported with the current player or browser
648 break;
649
650 case 'RangeError':
651 // the time was less than 0 or greater than the video’s duration
652 break;
653
654 default:
655 // some other error occurred
656 break;
657 }
658});
659```
660
661### removeCuePoint(id: string): Promise&lt;string, (UnsupportedError|InvalidCuePoint|Error)&gt;
662
663Remove the specified cue point using the id returned from `addCuePoint()` or
664from `getCuePoints()`.
665
666```js
667player.removeCuePoint('09ecf4e4-b587-42cf-ad9f-e666b679c9ab').then(function(id) {
668 // cue point was removed successfully
669}).catch(function(error) {
670 switch (error.name) {
671 case 'UnsupportedError':
672 // cue points are not supported with the current player or browser
673 break;
674
675 case 'InvalidCuePoint':
676 // a cue point with the id passed wasn’t found
677 break;
678
679 default:
680 // some other error occurred
681 break;
682 }
683});
684```
685
686### getCuePoints(): Promise&lt;array, (UnsupportedError|Error)&gt;
687
688Get an array of the cue points that have been added to the video.
689
690```js
691player.getCuePoints().then(function(cuePoints) {
692 // cuePoints = an array of cue point objects
693}).catch(function(error) {
694 switch (error.name) {
695 case 'UnsupportedError':
696 // cue points are not supported with the current player or browser
697 break;
698
699 default:
700 // some other error occurred
701 break;
702 }
703});
704```
705Each cue point object looks like this:
706
707```js
708{
709 "time": 15,
710 "data": {
711 "customKey": "customValue"
712 },
713 "id": "09ecf4e4-b587-42cf-ad9f-e666b679c9ab"
714}
715```
716
717### getCurrentTime(): Promise&lt;number, Error&gt;
718
719Get the current playback position in seconds.
720
721```js
722player.getCurrentTime().then(function(seconds) {
723 // seconds = the current playback position
724}).catch(function(error) {
725 // an error occurred
726});
727```
728
729### setCurrentTime(seconds: number): Promise&lt;number, (RangeError|Error)&gt;
730
731Set the current playback position in seconds. Once playback has started, if the
732player was paused, it will remain paused. Likewise, if the player was playing,
733it will resume playing once the video has buffered. Setting the current time
734before playback has started will cause playback to start.
735
736You can provide an accurate time and the player will attempt to seek to as close
737to that time as possible. The exact time will be the fulfilled value of the
738promise.
739
740```js
741player.setCurrentTime(30.456).then(function(seconds) {
742 // seconds = the actual time that the player seeked to
743}).catch(function(error) {
744 switch (error.name) {
745 case 'RangeError':
746 // the time was less than 0 or greater than the video’s duration
747 break;
748
749 default:
750 // some other error occurred
751 break;
752 }
753});
754```
755
756### getDuration(): Promise&lt;number, Error&gt;
757
758Get the duration of the video in seconds. It will be rounded to the nearest
759second before playback begins, and to the nearest thousandth of a second after
760playback begins.
761
762```js
763player.getDuration().then(function(duration) {
764 // duration = the duration of the video in seconds
765}).catch(function(error) {
766 // an error occurred
767});
768```
769
770### getEnded(): Promise&lt;boolean, Error&gt;
771
772Get the ended state of the video. The video has ended if
773`currentTime === duration`.
774
775```js
776player.getEnded().then(function(ended) {
777 // ended = whether or not the video has ended
778}).catch(function(error) {
779 // an error occurred
780});
781```
782
783### getLoop(): Promise&lt;boolean, Error&gt;
784
785Get the loop state of the player.
786
787```js
788player.getLoop().then(function(loop) {
789 // loop = whether loop is turned on or not
790}).catch(function(error) {
791 // an error occurred
792});
793```
794
795### setLoop(loop: boolean): Promise&lt;boolean, Error&gt;
796
797Set the loop state of the player. When set to `true`, the player will start over
798immediately once playback ends. *Note:* when loop is turned on, the `ended`
799event will not fire.
800
801```js
802player.setLoop(true).then(function(loop) {
803 // loop was turned on
804}).catch(function(error) {
805 // an error occurred
806});
807```
808
809### getMuted(): Promise&lt;boolean, Error&gt;
810
811Get the muted state of the player.
812
813```js
814player.getMuted().then(function(muted) {
815 // muted = whether muted is turned on or not
816}).catch(function(error) {
817 // an error occurred
818});
819```
820
821### setMuted(muted: boolean): Promise&lt;boolean, Error&gt;
822
823Set the muted state of the player. When set to `true`, the player volume will be muted.
824
825```js
826player.setMuted(true).then(function(muted) {
827 // muted was turned on
828}).catch(function(error) {
829 // an error occurred
830});
831```
832
833### getPaused(): Promise&lt;boolean, Error&gt;
834
835Get the paused state of the player.
836
837```js
838player.getPaused().then(function(paused) {
839 // paused = whether or not the player is paused
840}).catch(function(error) {
841 // an error occurred
842});
843```
844
845### getPlaybackRate(): Promise&lt;number, Error&gt;
846
847Get the playback rate of the player on a scale from `0.5` to `2`.
848
849```js
850player.getPlaybackRate().then(function(playbackRate) {
851 // playbackRate = a numeric value of the current playback rate
852}).catch(function(error) {
853 // an error occurred
854});
855```
856
857### setPlaybackRate(playbackRate: number): Promise&lt;number, (RangeError|Error)&gt;
858
859Set the playback rate of the player on a scale from `0.5` to `2` (available to PRO and Business accounts). When set
860via the API, the playback rate will not be synchronized to other
861players or stored as the viewer's preference.
862
863```js
864player.setPlaybackRate(0.5).then(function(playbackRate) {
865 // playback rate was set
866}).catch(function(error) {
867 switch (error.name) {
868 case 'RangeError':
869 // the playback rate was less than 0.5 or greater than 2
870 break;
871
872 default:
873 // some other error occurred
874 break;
875 }
876});
877```
878
879### getPlayed(): Promise&lt;array, Error&gt;
880
881Get the played time ranges of the video.
882
883```js
884player.getPlayed().then(function(played) {
885 // played = array values of the played video time ranges.
886}).catch(function(error) {
887 // an error occurred
888});
889```
890
891### getSeekable(): Promise&lt;array, Error&gt;
892
893Get the video time ranges that are seekable.
894
895```js
896player.getSeekable().then(function(seekable) {
897 // seekable = array values of the seekable video time ranges.
898}).catch(function(error) {
899 // an error occurred
900});
901```
902
903### getSeeking(): Promise&lt;boolean, Error&gt;
904
905Get if the player is currently seeking.
906
907```js
908player.getSeeking().then(function(seeking) {
909 // seeking = whether the player is seeking or not
910}).catch(function(error) {
911 // an error occurred
912});
913```
914
915### getTextTracks(): Promise&lt;object[], Error&gt;
916
917Get an array of the text tracks that exist for the video. For example:
918
919```js
920player.getTextTracks().then(function(tracks) {
921 // tracks = an array of track objects
922}).catch(function(error) {
923 // an error occurred
924});
925```
926
927Each track object looks like this:
928
929```js
930{
931 "label": "English CC",
932 "language": "en",
933 "kind": "captions",
934 "mode": "showing"
935}
936```
937
938Kind can be either `captions` or `subtitles`. The mode can be either `showing`
939or `disabled`. Only one track can be `showing` at any given time; the rest will
940be `disabled`.
941
942### getVideoEmbedCode(): Promise&lt;string, Error&gt;
943
944Get the `<iframe>` embed code for the video.
945
946```js
947player.getVideoEmbedCode().then(function(embedCode) {
948 // embedCode = <iframe> embed code
949}).catch(function(error) {
950 // an error occurred
951});
952```
953
954### getVideoId(): Promise&lt;number, Error&gt;
955
956Get the id of the video.
957
958```js
959player.getVideoId().then(function(id) {
960 // id = the video id
961}).catch(function(error) {
962 // an error occurred
963});
964```
965
966### getVideoTitle(): Promise&lt;string, Error&gt;
967
968Get the title of the video.
969
970```js
971player.getVideoTitle().then(function(title) {
972 // title = the title of the video
973}).catch(function(error) {
974 // an error occurred
975});
976```
977
978### getVideoWidth(): Promise&lt;number, Error&gt;
979
980Get the native width of the currently‐playing video. The width of the highest
981resolution available will be used before playback begins.
982
983```js
984player.getVideoWidth().then(function(width) {
985 // width = the width of the video that is currently playing
986}).catch(function(error) {
987 // an error occurred
988});
989```
990
991### getVideoHeight(): Promise&lt;number, Error&gt;
992
993Get the native height of the currently‐playing video. The height of the highest
994resolution available will be used before playback begins.
995
996```js
997player.getVideoHeight().then(function(height) {
998 // height = the height of the video that is currently playing
999}).catch(function(error) {
1000 // an error occurred
1001});
1002```
1003
1004To get both the width and height, you can do this:
1005
1006```js
1007Promise.all([player.getVideoWidth(), player.getVideoHeight()]).then(function(dimensions) {
1008 var width = dimensions[0];
1009 var height = dimensions[1];
1010});
1011```
1012
1013### getVideoUrl(): Promise&lt;string, (PrivacyError|Error)&gt;
1014
1015Get the [vimeo.com](https://vimeo.com) url for the video.
1016
1017```js
1018player.getVideoUrl().then(function(url) {
1019 // url = the vimeo.com url for the video
1020}).catch(function(error) {
1021 switch (error.name) {
1022 case 'PrivacyError':
1023 // the url isn’t available because of the video’s privacy setting
1024 break;
1025
1026 default:
1027 // some other error occurred
1028 break;
1029 }
1030});
1031```
1032
1033### getVolume(): Promise&lt;number, Error&gt;
1034
1035Get the current volume level of the player on a scale from `0` to `1`.
1036
1037Most mobile devices do not support an independent volume from the system volume.
1038In those cases, this method will always return `1`.
1039
1040```js
1041player.getVolume().then(function(volume) {
1042 // volume = the volume level of the player
1043}).catch(function(error) {
1044 // an error occurred
1045});
1046```
1047
1048### setVolume(volume: number): Promise&lt;number, (RangeError|Error)&gt;
1049
1050Set the volume of the player on a scale from `0` to `1`. When set via the API,
1051the volume level will not be synchronized to other players or stored as the
1052viewer’s preference.
1053
1054Most mobile devices (including iOS and Android) do not support setting the
1055volume because the volume is controlled at the system level. An error will *not*
1056be triggered in that situation.
1057
1058```js
1059player.setVolume(0.5).then(function(volume) {
1060 // volume was set
1061}).catch(function(error) {
1062 switch (error.name) {
1063 case 'RangeError':
1064 // the volume was less than 0 or greater than 1
1065 break;
1066
1067 default:
1068 // some other error occurred
1069 break;
1070 }
1071});
1072```
1073
1074## Events
1075
1076You can listen for events in the player by attaching a callback using `.on()`:
1077
1078```js
1079player.on('eventName', function(data) {
1080 // data is an object containing properties specific to that event
1081});
1082```
1083
1084The events are equivalent to the HTML5 video events (except for `cuechange`,
1085which is slightly different).
1086
1087To remove a listener, call `.off()` with the callback function:
1088
1089```js
1090var callback = function() {};
1091
1092player.off('eventName', callback);
1093```
1094
1095If you pass only an event name, all listeners for that event will be removed.
1096
1097### play
1098
1099Triggered when the video plays.
1100
1101```js
1102{
1103 duration: 61.857
1104 percent: 0
1105 seconds: 0
1106}
1107```
1108
1109### pause
1110
1111Triggered when the video pauses.
1112
1113```js
1114{
1115 duration: 61.857
1116 percent: 0
1117 seconds: 0
1118}
1119```
1120
1121### ended
1122
1123Triggered any time the video playback reaches the end. *Note:* when loop is
1124turned on, the `ended` event will not fire.
1125
1126```js
1127{
1128 duration: 61.857
1129 percent: 1
1130 seconds: 61.857
1131}
1132```
1133
1134### timeupdate
1135
1136Triggered as the `currentTime` of the video updates. It generally fires every
1137250ms, but it may vary depending on the browser.
1138
1139```js
1140{
1141 duration: 61.857
1142 percent: 0.049
1143 seconds: 3.034
1144}
1145```
1146
1147### progress
1148
1149Triggered as the video is loaded. Reports back the amount of the video that has
1150been buffered.
1151
1152```js
1153{
1154 duration: 61.857
1155 percent: 0.502
1156 seconds: 31.052
1157}
1158```
1159
1160### seeking
1161
1162Triggered when the player starts seeking to a specific time. A `timeupdate` event will
1163also be fired at the same time.
1164
1165```js
1166{
1167 duration: 61.857
1168 percent: 0.485
1169 seconds: 30
1170}
1171```
1172
1173### seeked
1174
1175Triggered when the player seeks to a specific time. A `timeupdate` event will
1176also be fired at the same time.
1177
1178```js
1179{
1180 duration: 61.857
1181 percent: 0.485
1182 seconds: 30
1183}
1184```
1185
1186### texttrackchange
1187
1188Triggered when the active text track (captions/subtitles) changes. The values
1189will be null if text tracks are turned off.
1190
1191```js
1192{
1193 kind: "captions",
1194 label: "English CC",
1195 language: "en"
1196}
1197```
1198
1199### cuechange
1200
1201Triggered when the active cue for the current text track changes. It also fires
1202when the active text track changes. There may be multiple cues active.
1203
1204```js
1205{
1206 cues: [
1207 {
1208 html: "<i>Here at Vimeo, there's always <br>one thing on our minds:</i>",
1209 text: "<i>Here at Vimeo, there's always ↵one thing on our minds:</i>"
1210 }
1211 ],
1212 kind: "captions",
1213 label: "English CC",
1214 language: "en"
1215}
1216```
1217
1218The `text` property of each cue is the raw value parsed from the caption or
1219subtitle file. The `html` property contains the HTML that the Player renders for
1220that cue.
1221
1222### cuepoint
1223
1224Triggered when the current time hits a registered cue point.
1225
1226```js
1227{
1228 time: 15,
1229 data: {
1230 customKey: 'customValue'
1231 },
1232 id: "40f5722b-09aa-4060-a887-3c81aaa37cce"
1233}
1234```
1235
1236The `data` property will be the custom data provided in the `addCuePoint()`
1237call, or an empty object if none was provided.
1238
1239### volumechange
1240
1241Triggered when the volume in the player changes. Some devices do not support
1242setting the volume of the video independently from the system volume, so this
1243event will never fire on those devices.
1244
1245```js
1246{
1247 volume: 0.5
1248}
1249```
1250
1251### playbackratechange
1252
1253Triggered when the playback rate of the video in the player changes. The ability to change rate can be disabled by the creator
1254and the event will not fire for those videos. The new playback rate is returned with the event.
1255
1256```js
1257{
1258 playbackRate: 1.5
1259}
1260```
1261
1262### bufferstart
1263
1264Triggered when buffering starts in the player. This is also triggered during preload and while seeking. There is no associated data with this event.
1265
1266
1267### bufferend
1268
1269Triggered when buffering ends in the player. This is also triggered at the end of preload and seeking. There is no associated data with this event.
1270
1271
1272### error
1273
1274Triggered when some kind of error is generated in the player. In general if you
1275are using this API library, you should use `.catch()` on each method call
1276instead of globally listening for error events.
1277
1278If the error was generated from a method call, the name of that method will be
1279included.
1280
1281```js
1282{
1283 message: "#984220 does not meet minimum contrast ratio. We recommend using brighter colors. (You could try #d35e30 instead.) See WCAG 2.0 guidelines: http://www.w3.org/TR/WCAG/#visual-audio-contrast"
1284 method: "setColor"
1285 name: "ContrastError"
1286}
1287```
1288
1289### loaded
1290
1291Triggered when a new video is loaded in the player.
1292
1293```js
1294{
1295 id: 76979871
1296}
1297```
1298
1299## Embed Options
1300
1301These options are available to use as `data-vimeo-` attributes on elements or as
1302an object passed to the `Vimeo.Player` constructor. More information on embed options can be found in the [Vimeo Help Center](https://help.vimeo.com/hc/en-us/articles/360001494447-Using-Player-Parameters).
1303
1304option | default | description
1305----------- | -------- | -----------
1306id _or_ url | | **Required.** Either the id or the url of the video.
1307autopause | `true` | Pause this video automatically when another one plays.
1308autoplay | `false` | Automatically start playback of the video. Note that this won’t work on some devices.
1309background | `false` | Enable the player's background mode which hides the controls, autoplays and loops the video (available to Plus, PRO, or Business members).
1310byline | `true` | Show the byline on the video.
1311color | `00adef` | Specify the color of the video controls. Colors may be overridden by the embed settings of the video.
1312controls | `true` | This parameter will hide all elements in the player (play bar, sharing buttons, etc) for a chromeless experience. ⚠️Warning: When using this parameter, the play bar and UI will be hidden. To start playback for your viewers, you'll need to either enable autoplay or use our player SDK to start and control playback. (available to Plus, PRO, or Business members)
1313dnt | `false` | Block the player from tracking any session data, including cookies.
1314height | | The exact height of the video. Defaults to the height of the largest available version of the video.
1315loop | `false` | Play the video again when it reaches the end.
1316responsive | `false` | Resize according their parent element (experimental)
1317maxheight | | Same as height, but video will not exceed the native size of the video.
1318maxwidth | | Same as width, but video will not exceed the native size of the video.
1319muted | `false` | Mute this video on load. Required to autoplay in certain browsers.
1320playsinline | `true` | Play video inline on mobile devices, to automatically go fullscreen on playback set this parameter to `false`.
1321portrait | `true` | Show the portrait on the video.
1322quality | | Vimeo Plus, PRO, and Business members can default an embedded video to a specific quality on desktop. Possible values: `4K`, `2K`, `1080p`, `720p`, `540p`, `360p` and `240p` https://help.vimeo.com/hc/en-us/articles/224983008-Setting-default-quality-for-embedded-videos
1323speed | `false` | Show the speed controls in the preferences menu and enable playback rate API (available to PRO and Business accounts).
1324texttrack | | Turn captions/subtitles on for a specific language by default. If you enter a language preference that hasn't yet been uploaded for your particular video, the text track parameter will be ignored, and your embedded video may load with CC or subtitles disabled by default. Supports lowercase language code (such as: `fr`, `es`, `de`, `en`). You can find a full list of popular language codes [here](https://www.andiamo.co.uk/resources/iso-language-codes/).
1325title | `true` | Show the title on the video.
1326transparent | `true` | The responsive player and transparent background are enabled by default, to disable set this parameter to `false`.
1327width | | The exact width of the video. Defaults to the width of the largest available version of the video.
1328