1
0
Fork 0

Add duration in embed api playbackStatusUpdate

This commit is contained in:
Chocobozzz 2020-04-08 14:51:44 +02:00
parent afd1a6ed49
commit 6ccdf9d53e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 7 additions and 3 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "@peertube/embed-api", "name": "@peertube/embed-api",
"private": false, "private": false,
"version": "0.0.3", "version": "0.0.4",
"description": "API to communicate with the PeerTube player embed", "description": "API to communicate with the PeerTube player embed",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

View file

@ -85,12 +85,14 @@ export class PeerTubeEmbedApi {
setInterval(() => { setInterval(() => {
const position = this.element.currentTime const position = this.element.currentTime
const volume = this.element.volume const volume = this.element.volume
const duration = this.element.duration
this.channel.notify({ this.channel.notify({
method: 'playbackStatusUpdate', method: 'playbackStatusUpdate',
params: { params: {
position, position,
volume, volume,
duration: this.embed.player.duration(),
playbackState: currentState playbackState: currentState
} }
}) })

View file

@ -8,7 +8,7 @@ window.addEventListener('load', async () => {
const videoId = lastPart.indexOf('?') === -1 ? lastPart : lastPart.split('?')[ 0 ] const videoId = lastPart.indexOf('?') === -1 ? lastPart : lastPart.split('?')[ 0 ]
const iframe = document.createElement('iframe') 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') const mainElement = document.querySelector('#host')
mainElement.appendChild(iframe) mainElement.appendChild(iframe)

View file

@ -113,12 +113,14 @@ You can subscribe to events by using `addEventListener()`. See above for details
## Event `playbackStatusUpdate` ## 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 ```json
{ {
"position": 22.3, "position": 22.3,
"volume": 0.9, "volume": 0.9,
"duration": "171.37499",
"playbackState": "playing" "playbackState": "playing"
} }
``` ```