diff options
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 4fd5a9be2..e9fb90c61 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -11,10 +11,12 @@ import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution | |||
11 | import { PeertubeChunkStore } from './peertube-chunk-store' | 11 | import { PeertubeChunkStore } from './peertube-chunk-store' |
12 | import { | 12 | import { |
13 | getAverageBandwidthInStore, | 13 | getAverageBandwidthInStore, |
14 | getStoredLastSubtitle, | ||
14 | getStoredMute, | 15 | getStoredMute, |
15 | getStoredVolume, | 16 | getStoredVolume, |
16 | getStoredWebTorrentEnabled, | 17 | getStoredWebTorrentEnabled, |
17 | saveAverageBandwidth, | 18 | saveAverageBandwidth, |
19 | saveLastSubtitle, | ||
18 | saveMuteInStore, | 20 | saveMuteInStore, |
19 | saveVolumeInStore | 21 | saveVolumeInStore |
20 | } from './peertube-player-local-storage' | 22 | } from './peertube-player-local-storage' |
@@ -67,10 +69,11 @@ class PeerTubePlugin extends Plugin { | |||
67 | private currentVideoFile: VideoFile | 69 | private currentVideoFile: VideoFile |
68 | private torrent: WebTorrent.Torrent | 70 | private torrent: WebTorrent.Torrent |
69 | private videoCaptions: VideoJSCaption[] | 71 | private videoCaptions: VideoJSCaption[] |
72 | private defaultSubtitle: string | ||
70 | 73 | ||
71 | private renderer: any | 74 | private renderer: any |
72 | private fakeRenderer: any | 75 | private fakeRenderer: any |
73 | private destoyingFakeRenderer = false | 76 | private destroyingFakeRenderer = false |
74 | 77 | ||
75 | private autoResolution = true | 78 | private autoResolution = true |
76 | private forbidAutoResolution = false | 79 | private forbidAutoResolution = false |
@@ -106,11 +109,34 @@ class PeerTubePlugin extends Plugin { | |||
106 | if (this.autoplay === true) this.player.addClass('vjs-has-autoplay') | 109 | if (this.autoplay === true) this.player.addClass('vjs-has-autoplay') |
107 | 110 | ||
108 | this.player.ready(() => { | 111 | this.player.ready(() => { |
112 | const playerOptions = this.player.options_ | ||
113 | |||
109 | const volume = getStoredVolume() | 114 | const volume = getStoredVolume() |
110 | if (volume !== undefined) this.player.volume(volume) | 115 | if (volume !== undefined) this.player.volume(volume) |
111 | const muted = getStoredMute() | 116 | |
117 | const muted = playerOptions.muted !== undefined ? playerOptions.muted : getStoredMute() | ||
112 | if (muted !== undefined) this.player.muted(muted) | 118 | if (muted !== undefined) this.player.muted(muted) |
113 | 119 | ||
120 | this.defaultSubtitle = options.subtitle || getStoredLastSubtitle() | ||
121 | |||
122 | this.player.on('volumechange', () => { | ||
123 | saveVolumeInStore(this.player.volume()) | ||
124 | saveMuteInStore(this.player.muted()) | ||
125 | }) | ||
126 | |||
127 | this.player.textTracks().on('change', () => { | ||
128 | const showing = this.player.textTracks().tracks_.find((t: { kind: string, mode: string }) => { | ||
129 | return t.kind === 'captions' && t.mode === 'showing' | ||
130 | }) | ||
131 | |||
132 | if (!showing) { | ||
133 | saveLastSubtitle('off') | ||
134 | return | ||
135 | } | ||
136 | |||
137 | saveLastSubtitle(showing.language) | ||
138 | }) | ||
139 | |||
114 | this.player.duration(options.videoDuration) | 140 | this.player.duration(options.videoDuration) |
115 | 141 | ||
116 | this.initializePlayer() | 142 | this.initializePlayer() |
@@ -124,11 +150,6 @@ class PeerTubePlugin extends Plugin { | |||
124 | this.runAutoQualitySchedulerTimer = setTimeout(() => this.runAutoQualityScheduler(), this.CONSTANTS.AUTO_QUALITY_SCHEDULER) | 150 | this.runAutoQualitySchedulerTimer = setTimeout(() => this.runAutoQualityScheduler(), this.CONSTANTS.AUTO_QUALITY_SCHEDULER) |
125 | }) | 151 | }) |
126 | }) | 152 | }) |
127 | |||
128 | this.player.on('volumechange', () => { | ||
129 | saveVolumeInStore(this.player.volume()) | ||
130 | saveMuteInStore(this.player.muted()) | ||
131 | }) | ||
132 | } | 153 | } |
133 | 154 | ||
134 | dispose () { | 155 | dispose () { |
@@ -599,6 +620,9 @@ class PeerTubePlugin extends Plugin { | |||
599 | this.player.src = this.savePlayerSrcFunction | 620 | this.player.src = this.savePlayerSrcFunction |
600 | this.player.src(httpUrl) | 621 | this.player.src(httpUrl) |
601 | 622 | ||
623 | // We changed the source, so reinit captions | ||
624 | this.initCaptions() | ||
625 | |||
602 | return this.tryToPlay(err => { | 626 | return this.tryToPlay(err => { |
603 | if (err && done) return done(err) | 627 | if (err && done) return done(err) |
604 | 628 | ||
@@ -657,14 +681,14 @@ class PeerTubePlugin extends Plugin { | |||
657 | } | 681 | } |
658 | 682 | ||
659 | private renderFileInFakeElement (file: WebTorrent.TorrentFile, delay: number) { | 683 | private renderFileInFakeElement (file: WebTorrent.TorrentFile, delay: number) { |
660 | this.destoyingFakeRenderer = false | 684 | this.destroyingFakeRenderer = false |
661 | 685 | ||
662 | const fakeVideoElem = document.createElement('video') | 686 | const fakeVideoElem = document.createElement('video') |
663 | renderVideo(file, fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => { | 687 | renderVideo(file, fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => { |
664 | this.fakeRenderer = renderer | 688 | this.fakeRenderer = renderer |
665 | 689 | ||
666 | // The renderer returns an error when we destroy it, so skip them | 690 | // The renderer returns an error when we destroy it, so skip them |
667 | if (this.destoyingFakeRenderer === false && err) { | 691 | if (this.destroyingFakeRenderer === false && err) { |
668 | console.error('Cannot render new torrent in fake video element.', err) | 692 | console.error('Cannot render new torrent in fake video element.', err) |
669 | } | 693 | } |
670 | 694 | ||
@@ -675,7 +699,7 @@ class PeerTubePlugin extends Plugin { | |||
675 | 699 | ||
676 | private destroyFakeRenderer () { | 700 | private destroyFakeRenderer () { |
677 | if (this.fakeRenderer) { | 701 | if (this.fakeRenderer) { |
678 | this.destoyingFakeRenderer = true | 702 | this.destroyingFakeRenderer = true |
679 | 703 | ||
680 | if (this.fakeRenderer.destroy) { | 704 | if (this.fakeRenderer.destroy) { |
681 | try { | 705 | try { |
@@ -695,9 +719,12 @@ class PeerTubePlugin extends Plugin { | |||
695 | label: caption.label, | 719 | label: caption.label, |
696 | language: caption.language, | 720 | language: caption.language, |
697 | id: caption.language, | 721 | id: caption.language, |
698 | src: caption.src | 722 | src: caption.src, |
723 | default: this.defaultSubtitle === caption.language | ||
699 | }, false) | 724 | }, false) |
700 | } | 725 | } |
726 | |||
727 | this.player.trigger('captionsChanged') | ||
701 | } | 728 | } |
702 | 729 | ||
703 | // Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657 | 730 | // Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657 |