diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-22 09:16:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-22 09:17:21 +0200 |
commit | e7eb5b399725afe7bae2dac27235a6e9478a2f12 (patch) | |
tree | c8e3dbbc50bfb1d6033b995b14977c934d625588 | |
parent | 0b33c5206023de0946b247e767087a518e0dec9a (diff) | |
download | PeerTube-e7eb5b399725afe7bae2dac27235a6e9478a2f12.tar.gz PeerTube-e7eb5b399725afe7bae2dac27235a6e9478a2f12.tar.zst PeerTube-e7eb5b399725afe7bae2dac27235a6e9478a2f12.zip |
Fix play on iOS (grumph)
-rw-r--r-- | client/src/app/videos/+video-watch/video-watch.component.ts | 1 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 20 | ||||
-rw-r--r-- | client/src/environments/environment.hmr.ts | 2 | ||||
-rw-r--r-- | client/src/standalone/videos/embed.html | 2 |
4 files changed, 19 insertions, 6 deletions
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index 127ae919d..35a7c04cc 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -340,6 +340,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
340 | const playerElementWrapper = this.elementRef.nativeElement.querySelector('#video-element-wrapper') | 340 | const playerElementWrapper = this.elementRef.nativeElement.querySelector('#video-element-wrapper') |
341 | this.playerElement = document.createElement('video') | 341 | this.playerElement = document.createElement('video') |
342 | this.playerElement.className = 'video-js vjs-peertube-skin' | 342 | this.playerElement.className = 'video-js vjs-peertube-skin' |
343 | this.playerElement.setAttribute('playsinline', 'true') | ||
343 | playerElementWrapper.appendChild(this.playerElement) | 344 | playerElementWrapper.appendChild(this.playerElement) |
344 | 345 | ||
345 | const videojsOptions = getVideojsOptions({ | 346 | const videojsOptions = getVideojsOptions({ |
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index ac04421a7..5789641fe 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -63,7 +63,8 @@ class PeerTubePlugin extends Plugin { | |||
63 | constructor (player: videojs.Player, options: PeertubePluginOptions) { | 63 | constructor (player: videojs.Player, options: PeertubePluginOptions) { |
64 | super(player, options) | 64 | super(player, options) |
65 | 65 | ||
66 | this.autoplay = options.autoplay | 66 | // Disable auto play on iOS |
67 | this.autoplay = options.autoplay && this.isIOS() === false | ||
67 | 68 | ||
68 | this.startTime = options.startTime | 69 | this.startTime = options.startTime |
69 | this.videoFiles = options.videoFiles | 70 | this.videoFiles = options.videoFiles |
@@ -180,6 +181,7 @@ class PeerTubePlugin extends Plugin { | |||
180 | oldTorrent.removePeer(oldTorrent['ws']) | 181 | oldTorrent.removePeer(oldTorrent['ws']) |
181 | } | 182 | } |
182 | 183 | ||
184 | // Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution) | ||
183 | this.addTorrentDelay = setTimeout(() => { | 185 | this.addTorrentDelay = setTimeout(() => { |
184 | this.flushVideoFile(previousVideoFile) | 186 | this.flushVideoFile(previousVideoFile) |
185 | 187 | ||
@@ -337,6 +339,12 @@ class PeerTubePlugin extends Plugin { | |||
337 | this.tryToPlay() | 339 | this.tryToPlay() |
338 | }) | 340 | }) |
339 | } else { | 341 | } else { |
342 | // Don't try on iOS that does not support MediaSource | ||
343 | if (this.isIOS()) { | ||
344 | this.currentVideoFile = this.videoFiles[0] | ||
345 | return this.fallbackToHttp(undefined, false) | ||
346 | } | ||
347 | |||
340 | // Proxy first play | 348 | // Proxy first play |
341 | const oldPlay = this.player.play.bind(this.player) | 349 | const oldPlay = this.player.play.bind(this.player) |
342 | this.player.play = () => { | 350 | this.player.play = () => { |
@@ -439,7 +447,7 @@ class PeerTubePlugin extends Plugin { | |||
439 | return fetch(this.videoViewUrl, { method: 'POST' }) | 447 | return fetch(this.videoViewUrl, { method: 'POST' }) |
440 | } | 448 | } |
441 | 449 | ||
442 | private fallbackToHttp (done: Function) { | 450 | private fallbackToHttp (done?: Function, play = true) { |
443 | this.flushVideoFile(this.currentVideoFile, true) | 451 | this.flushVideoFile(this.currentVideoFile, true) |
444 | this.torrent = null | 452 | this.torrent = null |
445 | 453 | ||
@@ -449,9 +457,9 @@ class PeerTubePlugin extends Plugin { | |||
449 | const httpUrl = this.currentVideoFile.fileUrl | 457 | const httpUrl = this.currentVideoFile.fileUrl |
450 | this.player.src = this.savePlayerSrcFunction | 458 | this.player.src = this.savePlayerSrcFunction |
451 | this.player.src(httpUrl) | 459 | this.player.src(httpUrl) |
452 | this.player.play() | 460 | if (play) this.tryToPlay() |
453 | 461 | ||
454 | return done() | 462 | if (done) return done() |
455 | } | 463 | } |
456 | 464 | ||
457 | private handleError (err: Error | string) { | 465 | private handleError (err: Error | string) { |
@@ -466,6 +474,10 @@ class PeerTubePlugin extends Plugin { | |||
466 | this.player.removeClass('vjs-error-display-enabled') | 474 | this.player.removeClass('vjs-error-display-enabled') |
467 | } | 475 | } |
468 | 476 | ||
477 | private isIOS () { | ||
478 | return !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform) | ||
479 | } | ||
480 | |||
469 | private alterInactivity () { | 481 | private alterInactivity () { |
470 | let saveInactivityTimeout: number | 482 | let saveInactivityTimeout: number |
471 | 483 | ||
diff --git a/client/src/environments/environment.hmr.ts b/client/src/environments/environment.hmr.ts index 20e2b8fcd..78cc8a992 100644 --- a/client/src/environments/environment.hmr.ts +++ b/client/src/environments/environment.hmr.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | export const environment = { | 1 | export const environment = { |
2 | production: false, | 2 | production: false, |
3 | hmr: true, | 3 | hmr: true, |
4 | apiUrl: 'http://localhost:9000' | 4 | apiUrl: 'http://192.168.1.42:9000' |
5 | } | 5 | } |
diff --git a/client/src/standalone/videos/embed.html b/client/src/standalone/videos/embed.html index b60b03a22..2d1b48b38 100644 --- a/client/src/standalone/videos/embed.html +++ b/client/src/standalone/videos/embed.html | |||
@@ -17,7 +17,7 @@ | |||
17 | <div id="error-content"></div> | 17 | <div id="error-content"></div> |
18 | </div> | 18 | </div> |
19 | 19 | ||
20 | <video id="video-container" class="video-js vjs-peertube-skin"> | 20 | <video playsinline="true" id="video-container" class="video-js vjs-peertube-skin"> |
21 | </video> | 21 | </video> |
22 | 22 | ||
23 | </body> | 23 | </body> |