Implement better support for playback rate changes (#730)

* Implement better support for playback rate changes.

* Add isNaN check for duration.
This commit is contained in:
Kavin 2022-01-16 08:43:24 +00:00 committed by GitHub
parent 6948fb6269
commit 2bb7288451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -349,8 +349,10 @@ export default {
this.setPreference("volume", videoEl.volume); this.setPreference("volume", videoEl.volume);
}); });
videoEl.addEventListener("ratechange", () => { videoEl.addEventListener("ratechange", e => {
this.setPreference("rate", videoEl.playbackRate); const rate = videoEl.playbackRate;
if (rate > 0 && !isNaN(videoEl.duration) && !isNaN(videoEl.duration - e.timeStamp / 1000))
this.setPreference("rate", rate);
}); });
videoEl.addEventListener("ended", () => { videoEl.addEventListener("ended", () => {
@ -489,7 +491,10 @@ export default {
); );
}); });
videoEl.volume = this.getPreferenceNumber("volume", 1); videoEl.volume = this.getPreferenceNumber("volume", 1);
player.trickPlay(this.getPreferenceNumber("rate", 1)); const rate = this.getPreferenceNumber("rate", 1);
player.trickPlay(rate);
player.playbackRate = rate;
player.defaultPlaybackRate = rate;
}); });
}, },
async updateProgressDatabase(time) { async updateProgressDatabase(time) {