From e367da949bb97c3db8c2f9a28ea09eef93abb2f5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Sep 2021 16:08:59 +0200 Subject: Cleanup player quality change --- client/src/standalone/videos/embed-api.ts | 37 +++++++++---------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'client/src/standalone') diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index b5c9da431..8443cb7e9 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts @@ -139,15 +139,8 @@ export class PeerTubeEmbedApi { }) // PeerTube specific capabilities - if (this.isWebtorrent()) { - this.embed.player.webtorrent().on('autoResolutionUpdate', () => this.loadWebTorrentResolutions()) - this.embed.player.webtorrent().on('videoFileUpdate', () => this.loadWebTorrentResolutions()) - - this.loadWebTorrentResolutions() - } else { - this.embed.player.p2pMediaLoader().on('resolutionChange', () => this.loadP2PMediaLoaderResolutions()) - this.embed.player.p2pMediaLoader().on('resolutionsLoaded', () => this.loadP2PMediaLoaderResolutions()) - } + this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions()) + this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions()) this.embed.player.on('volumechange', () => { this.channel.notify({ @@ -183,23 +176,15 @@ export class PeerTubeEmbedApi { }) } - private loadP2PMediaLoaderResolutions () { - this.resolutions = [] - - const qualityLevels = this.embed.player.qualityLevels() - const currentResolutionId = this.embed.player.qualityLevels().selectedIndex - - for (let i = 0; i < qualityLevels.length; i++) { - const level = qualityLevels[i] - - this.resolutions.push({ - id: level.id, - label: level.height + 'p', - active: level.id === currentResolutionId, - width: level.width, - height: level.height - }) - } + private loadResolutions () { + this.resolutions = this.embed.player.peertubeResolutions().getResolutions() + .map(r => ({ + id: r.id, + label: r.height + 'p', + active: r.selected, + width: r.width, + height: r.height + })) this.channel.notify({ method: 'resolutionUpdate', -- cgit v1.2.3 From 89ac282e0437ae839e3d71566f25321f9b9384e9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Sep 2021 15:43:15 +0200 Subject: Fix embed api --- client/src/standalone/videos/embed-api.ts | 41 ++++-------------------------- client/src/standalone/videos/test-embed.ts | 2 -- 2 files changed, 5 insertions(+), 38 deletions(-) (limited to 'client/src/standalone') diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index 8443cb7e9..a28aeeaef 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts @@ -64,19 +64,12 @@ export class PeerTubeEmbedApi { if (this.isWebtorrent()) { if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return - // Auto resolution - if (resolutionId === -1) { - this.embed.player.webtorrent().enableAutoResolution() - return - } - - this.embed.player.webtorrent().disableAutoResolution() - this.embed.player.webtorrent().updateResolution(resolutionId) + this.embed.player.webtorrent().changeQuality(resolutionId) return } - this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId + this.embed.player.p2pMediaLoader().getHLSJS().currentLevel = resolutionId } private getCaptions (): PeerTubeTextTrack[] { @@ -142,6 +135,8 @@ export class PeerTubeEmbedApi { this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions()) this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions()) + this.loadResolutions() + this.embed.player.on('volumechange', () => { this.channel.notify({ method: 'volumeChange', @@ -150,37 +145,11 @@ export class PeerTubeEmbedApi { }) } - private loadWebTorrentResolutions () { - this.resolutions = [] - - const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId() - - for (const videoFile of this.embed.player.webtorrent().videoFiles) { - let label = videoFile.resolution.label - if (videoFile.fps && videoFile.fps >= 50) { - label += videoFile.fps - } - - this.resolutions.push({ - id: videoFile.resolution.id, - label, - src: videoFile.magnetUri, - active: videoFile.resolution.id === currentResolutionId, - height: videoFile.resolution.id - }) - } - - this.channel.notify({ - method: 'resolutionUpdate', - params: this.resolutions - }) - } - private loadResolutions () { this.resolutions = this.embed.player.peertubeResolutions().getResolutions() .map(r => ({ id: r.id, - label: r.height + 'p', + label: r.label, active: r.selected, width: r.width, height: r.height diff --git a/client/src/standalone/videos/test-embed.ts b/client/src/standalone/videos/test-embed.ts index 301c95d7b..7213cbf8b 100644 --- a/client/src/standalone/videos/test-embed.ts +++ b/client/src/standalone/videos/test-embed.ts @@ -84,8 +84,6 @@ window.addEventListener('load', async () => { captionEl.innerHTML = '' captions.forEach(c => { - console.log(c) - if (c.mode === 'showing') { const itemEl = document.createElement('strong') itemEl.innerText = `${c.label} (active)` -- cgit v1.2.3