Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add duration in embed api playbackStatusUpdate

Chocobozzz6ccdf9d53e4d
diff --git a/client/src/standalone/player/package.json b/client/src/standalone/player/package.json
index ba36b8ad3c..985097af52 100644
--- a/client/src/standalone/player/package.json
+++ b/client/src/standalone/player/package.json
@@ -1,7 +1,7 @@
{
"name": "@peertube/embed-api",
"private": false,
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "API to communicate with the PeerTube player embed",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts
index c5fbe07fa5..194465d4a4 100644
--- a/client/src/standalone/videos/embed-api.ts
+++ b/client/src/standalone/videos/embed-api.ts
@@ -85,12 +85,14 @@ export class PeerTubeEmbedApi {
setInterval(() => {
const position = this.element.currentTime
const volume = this.element.volume
+ const duration = this.element.duration
this.channel.notify({
method: 'playbackStatusUpdate',
params: {
position,
volume,
+ duration: this.embed.player.duration(),
playbackState: currentState
}
})
diff --git a/client/src/standalone/videos/test-embed.ts b/client/src/standalone/videos/test-embed.ts
index 202e86667c..a4b54782c7 100644
--- a/client/src/standalone/videos/test-embed.ts
+++ b/client/src/standalone/videos/test-embed.ts
@@ -8,7 +8,7 @@ window.addEventListener('load', async () => {
const videoId = lastPart.indexOf('?') === -1 ? lastPart : lastPart.split('?')[ 0 ]
const iframe = document.createElement('iframe')
- iframe.src = `/videos/embed/${videoId}?autoplay=1&controls=0&api=1`
+ iframe.src = `/videos/embed/${videoId}?api=1`
const mainElement = document.querySelector('#host')
mainElement.appendChild(iframe)
diff --git a/support/doc/api/embeds.md b/support/doc/api/embeds.md
index 80e03b487d..80d6c22793 100644
--- a/support/doc/api/embeds.md
+++ b/support/doc/api/embeds.md
@@ -113,12 +113,14 @@ 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"
}
```