]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - support/doc/api/embeds.md
Updated notification types in openapi reference
[github/Chocobozzz/PeerTube.git] / support / doc / api / embeds.md
index ca480006d9c603ea13df5583c053454655a1ff95..d64615764edab58af4d4677d691dab6344c583a5 100644 (file)
@@ -4,13 +4,14 @@ PeerTube lets you embed videos and programmatically control their playback. This
 
 ## Playground
 
-Any PeerTube embed URL (ie `https://my-instance.example.com/videos/embed/52a10666-3a18-4e73-93da-e8d3c12c305a`) can be viewed as an embedding playground which 
-allows you to test various aspects of PeerTube embeds. Simply replace `/embed` with `/test-embed` and visit the URL in a browser. 
+Any PeerTube embed URL (ie `https://my-instance.example.com/videos/embed/52a10666-3a18-4e73-93da-e8d3c12c305a`) can be viewed as an embedding playground which
+allows you to test various aspects of PeerTube embeds. Simply replace `/embed` with `/test-embed` and visit the URL in a browser.
 For instance, the playground URL for the above embed URL is `https://my-instance.example.com/videos/test-embed/52a10666-3a18-4e73-93da-e8d3c12c305a`.
 
 ## Quick Start
 
-Given an existing PeerTube embed `<iframe>`, one can use the PeerTube Embed API to control it by first including the library. You can include it via Yarn with:
+Given an existing PeerTube embed `<iframe>` **with API enabled** (`https://my-instance.example.com/videos/embed/52a10666-3a18-4e73-93da-e8d3c12c305a?api=1`),
+one can use the PeerTube Embed API to control it by first including the library. You can include it via Yarn with:
 
 ```
 yarn add @peertube/embed-api
@@ -27,7 +28,7 @@ import { PeerTubePlayer } from '@peertube/embed-api'
 Or use the minified build from NPM CDN in your HTML file:
 
 ```
-<script src="https://unpkg.com/@peertube/embed-api@0.0.1/build/player.min.js"></script>
+<script src="https://unpkg.com/@peertube/embed-api/build/player.min.js"></script>
 
 <script>
   const PeerTubePlayer = window['PeerTubePlayer']
@@ -45,7 +46,7 @@ await player.ready // wait for the player to be ready
 // now you can use it!
 player.play()
 player.seek(32)
-player.stop()
+player.pause()
 ```
 
 # Methods
@@ -94,11 +95,11 @@ Get the available playback rates, where `1` represents normal speed, `0.5` is ha
 
 Get the current playback rate. See `getPlaybackRates()` for more information.
 
-## `setPlaybackRate(rate : number) : Promise<void>`
+## `setPlaybackRate(rate: number) : Promise<void>`
 
 Set the current playback rate. The passed rate should be a value as returned by `getPlaybackRates()`.
 
-## `setVolume(factor : number) : Promise<void>`
+## `setVolume(factor: number) : Promise<void>`
 
 Set the playback volume. Value should be between `0` and `1`.
 
@@ -106,35 +107,52 @@ Set the playback volume. Value should be between `0` and `1`.
 
 Get the playback volume. Returns a value between `0` and `1`.
 
-# Events
+## `setCaption(id: string) : Promise<void>`
 
-You can subscribe to events by using `addEventListener()`. See above for details.
+Update current caption using the caption id.
+
+## `getCaptions(): Promise<{ id: string, label: string, src: string, mode: 'disabled' | 'showing' }>`
+
+Get video captions.
+
+## `playNextVideo(): Promise<void>`
+
+Play next video in playlist.
 
-## Event `play`
+## `playPreviousVideo(): Promise<void>`
 
-Fired when playback begins or is resumed after pausing.
+Play previous video in playlist.
 
-## Event `pause`
+## `getCurrentPosition(): Promise<void>`
 
-Fired when playback is paused.
+Get current position in playlist (starts from 1).
+
+# Events
+
+You can subscribe to events by using `addEventListener()`. See above for details.
 
 ## Event `playbackStatusUpdate`
 
-Fired every half second to provide the current status of playback. The parameter of the callback will resemble:
+Fired every half second to provide the current status of playback.
+The parameter of the callback will resemble:
 
 ```json
 {
   "position": 22.3,
   "volume": 0.9,
+  "duration": "171.37499",
   "playbackState": "playing"
 }
 ```
 
-The `volume` field contains the volume from `0` (silent) to `1` (full volume). The `playbackState` can be `playing` or `paused`. More states may be added later.
+`duration` field and `ended` `playbackState` are available in PeerTube >= 2.2.
+
+The `volume` field contains the volume from `0` (silent) to `1` (full volume).
+The `playbackState` can be `unstarted`, `playing`, `paused` or `ended`. More states may be added later.
 
 ## Event `playbackStatusChange`
 
-Fired when playback transitions between states, such as `pausing` and `playing`. More states may be added later.
+Fired when playback transitions between states, such as `paused` and `playing`. More states may be added later.
 
 ## Event `resolutionUpdate`