diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-17 14:14:54 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-17 14:15:30 +0100 |
commit | 3b019808ef529cacce7f40706441670309e231d1 (patch) | |
tree | 3fd6668e16943da46ca4be12d2c92aa360183edf /client/src/assets/player/peertube-videojs-plugin.ts | |
parent | 259dd796e6d93db8068ec47aac99a560f2818673 (diff) | |
download | PeerTube-3b019808ef529cacce7f40706441670309e231d1.tar.gz PeerTube-3b019808ef529cacce7f40706441670309e231d1.tar.zst PeerTube-3b019808ef529cacce7f40706441670309e231d1.zip |
Set last subtitle or subtitle in URL
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 44 |
1 files changed, 33 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..4a280b7ef 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 () { |
@@ -657,14 +678,14 @@ class PeerTubePlugin extends Plugin { | |||
657 | } | 678 | } |
658 | 679 | ||
659 | private renderFileInFakeElement (file: WebTorrent.TorrentFile, delay: number) { | 680 | private renderFileInFakeElement (file: WebTorrent.TorrentFile, delay: number) { |
660 | this.destoyingFakeRenderer = false | 681 | this.destroyingFakeRenderer = false |
661 | 682 | ||
662 | const fakeVideoElem = document.createElement('video') | 683 | const fakeVideoElem = document.createElement('video') |
663 | renderVideo(file, fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => { | 684 | renderVideo(file, fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => { |
664 | this.fakeRenderer = renderer | 685 | this.fakeRenderer = renderer |
665 | 686 | ||
666 | // The renderer returns an error when we destroy it, so skip them | 687 | // The renderer returns an error when we destroy it, so skip them |
667 | if (this.destoyingFakeRenderer === false && err) { | 688 | if (this.destroyingFakeRenderer === false && err) { |
668 | console.error('Cannot render new torrent in fake video element.', err) | 689 | console.error('Cannot render new torrent in fake video element.', err) |
669 | } | 690 | } |
670 | 691 | ||
@@ -675,7 +696,7 @@ class PeerTubePlugin extends Plugin { | |||
675 | 696 | ||
676 | private destroyFakeRenderer () { | 697 | private destroyFakeRenderer () { |
677 | if (this.fakeRenderer) { | 698 | if (this.fakeRenderer) { |
678 | this.destoyingFakeRenderer = true | 699 | this.destroyingFakeRenderer = true |
679 | 700 | ||
680 | if (this.fakeRenderer.destroy) { | 701 | if (this.fakeRenderer.destroy) { |
681 | try { | 702 | try { |
@@ -695,7 +716,8 @@ class PeerTubePlugin extends Plugin { | |||
695 | label: caption.label, | 716 | label: caption.label, |
696 | language: caption.language, | 717 | language: caption.language, |
697 | id: caption.language, | 718 | id: caption.language, |
698 | src: caption.src | 719 | src: caption.src, |
720 | default: this.defaultSubtitle === caption.language | ||
699 | }, false) | 721 | }, false) |
700 | } | 722 | } |
701 | } | 723 | } |