manelpb / videojs-qualityselector

Simple plugin that displays a dropdown with a list of possible videos based on its resolution, also changes the source when the user selects a desired option
MIT License
19 stars 11 forks source link

Resuming Playback Position Upon Quality Change #7

Open GlitterCakes opened 6 years ago

GlitterCakes commented 6 years ago

The previous plugin "videojs resolution switcher" for video js 5x is smart enough to resume playback at the same point in time upon changing resolutions. It would be great if this plugin could do the same.

I know this is considered a feature but to end users this definitely comes across as a bug.

sqlninja commented 6 years ago

To implement this I changed the following lines (68 - 85)

if (source) {
          this.player.src({ src: source.src, type: source.type });
          var whereYouAt = this.player.currentTime(); // <~~ Added this to get the current video position
          console.log({whereYouAt}); // <~~ logging position to console

          this.player.on('loadedmetadata', function () {
            _this.player.currentTime(whereYouAt); // <~~ Set the player back to the current position
            _this.player.play();

            Array.from(_this.containerDropdownElement.firstChild.childNodes).forEach(function (ele) {
              if (ele.dataset.code === quality.code) {
                ele.setAttribute('class', 'current');
              } else {
                ele.removeAttribute('class');
              }
            });
          });
        }
sqlninja commented 6 years ago

Added a PR for this changed PR15

w- commented 5 years ago

@sqlninja I want you to know this helped me immensely. Thank you.

There was a minor change from the PR required to make it work with latest version. (the change is in your comment above tho).

I noticed that when switching resolutions the poster image shows up again until the video is ready to stream. is there a way to default that to the loading indicator?

thanks

sqlninja commented 5 years ago

@w- Having not been in that code for a while, I'm just going to take a stab in the dark at this... I'd think you would need to set the loading indicator in the DOM on the resolutions change (possibly on click), and then handle the onSuccess of the resolution change callback to remove the loading indicator, and set it to the video. HTH

w- commented 5 years ago

cool thx.

tiantian-meng commented 5 years ago

@w- Having not been in that code for a while, I'm just going to take a stab in the dark at this... I'd think you would need to set the loading indicator in the DOM on the resolutions change (possibly on click), and then handle the onSuccess of the resolution change callback to remove the loading indicator, and set it to the video. HTH

hi

if (source) {
                this.player.src({src: source.src, type: source.type});
                const whereYouAt = this.player.currentTime();
                this.player.play();

                this.player.on('loadedmetadata', () => {
                    this.player.currentTime(whereYouAt);

                    Array.from(this.containerDropdownElement.firstChild.childNodes).forEach((ele) => {
                        if (ele.dataset.code === quality.code) {
                            ele.setAttribute('class', 'current');
                        } else {
                            ele.removeAttribute('class');
                        }
                    });
                });
            }

I'd think play() should be put on the outside.