silvermine / videojs-chromecast

MIT License
147 stars 74 forks source link

Video does not resume playing in browser after disconnecting from chromecast #174

Open ToshY opened 6 months ago

ToshY commented 6 months ago

Problem

When a video is playing on chromecast, and the chromecast is disconnected, the video is paused even though it should be playing according to _reloadTech.

Expected

Video should resume playing in browser if it was playing on the chromecast after disconnecting.

Reproduction

  1. Go to example: https://codepen.io/nanone/pen/jOJqyBq
  2. Cast the video to chromecast.
  3. Do not pause the video, and disconnect the chromecast.
  4. The video is now paused even though it should be playing.

Possible solutions

I've been debugging this, and if I put a player.load() inside the ready function, it seems to work.

   _reloadTech() {
      var player = this.player,
          currentTime = player.currentTime(),
          wasPaused = player.paused(),
          sources = player.currentSources();

      // Reload the current source(s) to re-lookup and use the currently available Tech.
      // The chromecast Tech gets used if `ChromecastSessionManager.isChromecastConnected`
      // is true (effectively, if a chromecast session is currently in progress),
      // otherwise Video.js continues to search through the Tech list for other eligible
      // Tech to use, such as the HTML5 player.
      player.src(sources);

      player.ready(function() {
         player.load(); // added this
         if (wasPaused) {
            player.pause();
         } else {
            player.play();
         }
         player.currentTime(currentTime || 0);
      });
   }

Please let me know if this is a OK solution, I will create a PR for it.

Versions videojs: 8.9.0 silvermine/videojs-chromecast: 1.5.0