const videojsOptions = {
controls: true,
poster: options.poster,
- autoplay: options.autoplay,
+ autoplay: false,
inactivityTimeout: options.inactivityTimeout,
playbackRates: [ 0.5, 1, 1.5, 2 ],
plugins: {
peertube: {
+ autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
videoFiles: options.videoFiles,
playerElement: options.playerElement,
videoViewUrl: options.videoViewUrl,
constructor (player: videojs.Player, options: PeertubePluginOptions) {
super(player, options)
- // Fix canplay event on google chrome by disabling default videojs autoplay
- this.autoplay = this.player.options_.autoplay
- this.player.options_.autoplay = false
+ this.autoplay = options.autoplay
this.startTime = options.startTime
this.videoFiles = options.videoFiles
if (err) return this.fallbackToHttp(done)
- if (!this.player.paused()) {
- const playPromise = this.player.play()
- if (playPromise !== undefined) return playPromise.then(done)
-
- return done()
- }
+ if (!this.player.paused()) return this.tryToPlay(done)
return done()
})
this.trigger('autoResolutionUpdate')
}
+ private tryToPlay (done?: Function) {
+ if (!done) done = function () { /* empty */ }
+
+ const playPromise = this.player.play()
+ if (playPromise !== undefined) {
+ return playPromise.then(done)
+ .catch(err => {
+ console.error(err)
+ this.player.pause()
+ this.player.posterImage.show()
+ this.player.removeClass('vjs-has-autoplay')
+
+ return done()
+ })
+ }
+
+ return done()
+ }
+
private seek (time: number) {
this.player.currentTime(time)
this.player.handleTechSeeked_()
if (this.autoplay === true) {
this.player.posterImage.hide()
- this.updateVideoFile(undefined, 0, () => this.seek(this.startTime))
+ this.updateVideoFile(undefined, 0, () => {
+ this.seek(this.startTime)
+ this.tryToPlay()
+ })
} else {
// Proxy first play
const oldPlay = this.player.play.bind(this.player)