Fix player error when the media is not supported
authorChocobozzz <me@florianbigard.com>
Mon, 26 Mar 2018 13:29:04 +0000 (15:29 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 26 Mar 2018 13:29:04 +0000 (15:29 +0200)
client/src/assets/player/peertube-videojs-plugin.ts
client/src/assets/player/video-renderer.ts

index 277603c9be619eecbeb8297dfb0c00170663b656..52846503d93a6d91bf67cddadcbbd120d5c4f8af 100644 (file)
@@ -270,7 +270,7 @@ class PeerTubePlugin extends Plugin {
     this.playerElement = options.playerElement
 
     this.player.ready(() => {
-      this.initializePlayer(options)
+      this.initializePlayer()
       this.runTorrentInfoScheduler()
       this.runViewAdd()
     })
@@ -331,9 +331,10 @@ class PeerTubePlugin extends Plugin {
 
       const options = { autoplay: true, controls: true }
       renderVideo(torrent.files[0], this.playerElement, options,(err, renderer) => {
+        this.renderer = renderer
+
         if (err) return this.fallbackToHttp()
 
-        this.renderer = renderer
         if (!this.player.paused()) {
           const playPromise = this.player.play()
           if (playPromise !== undefined) return playPromise.then(done)
@@ -406,7 +407,7 @@ class PeerTubePlugin extends Plugin {
     this.updateVideoFile(undefined, () => this.player.play())
   }
 
-  private initializePlayer (options: PeertubePluginOptions) {
+  private initializePlayer () {
     if (this.autoplay === true) {
       this.updateVideoFile(undefined, () => this.player.play())
     } else {
index e3415abd336c25e028ee098736fb76c2dfed8652..4affb43cf1c951aa87cf23c3d246c971b83a9d7d 100644 (file)
@@ -58,13 +58,11 @@ function renderMedia (file, elem: HTMLVideoElement, opts: RenderMediaOptions, ca
     const codecs = getCodec(file.name, useVP9)
 
     prepareElem()
-    preparedElem.addEventListener('error', function onError(err) {
-      // Try with vp9 before returning an error
-      if (codecs.indexOf('vp8') !== -1) {
-        preparedElem.removeEventListener('error', onError)
+    preparedElem.addEventListener('error', function onError (err) {
+      preparedElem.removeEventListener('error', onError)
 
-        return fallbackToMediaSource(true)
-      }
+      // Try with vp9 before returning an error
+      if (codecs.indexOf('vp8') !== -1) return fallbackToMediaSource(true)
 
       return callback(err)
     })