Skip to content

Commit

Permalink
will HTMLMediaElement timeupdate run faster than 4hz?
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Apr 27, 2024
1 parent a25a724 commit 62a36d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
46 changes: 29 additions & 17 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,35 @@ ImprovedTube.initPlayer = function () {
}
};

ImprovedTube.playerOnTimeUpdate = function () {
if (ImprovedTube.video_src !== this.src) {
ImprovedTube.video_src = this.src;

if (ImprovedTube.initialVideoUpdateDone !== true) {
ImprovedTube.playerQuality();
}
} else if (ImprovedTube.latestVideoDuration !== this.duration) {
ImprovedTube.latestVideoDuration = this.duration;

ImprovedTube.playerQuality();
}

ImprovedTube.alwaysShowProgressBar();
ImprovedTube.playerRemainingDuration();

ImprovedTube.played_time += .25;
var timeUpdateInterval = null;
var noTimeUpdate = null;

ImprovedTube.playerOnTimeUpdate = function() {
var currentTime = Date.now();
if (!timeUpdateInterval) {
timeUpdateInterval = setInterval(function() {
if (ImprovedTube.video_src !== this.src) {
ImprovedTube.video_src = this.src;

if (ImprovedTube.initialVideoUpdateDone !== true) {
ImprovedTube.playerQuality();
}
} else if (ImprovedTube.latestVideoDuration !== this.duration) {
ImprovedTube.latestVideoDuration = this.duration;

ImprovedTube.playerQuality();
}

ImprovedTube.alwaysShowProgressBar();
ImprovedTube.playerRemainingDuration();
ImprovedTube.played_time += .5;
}, 500);
}
clearInterval(noTimeUpdate);
noTimeUpdate = setTimeout(function() {
clearInterval(timeUpdateInterval);
timeUpdateInterval = null;
}, 987);
};

ImprovedTube.playerOnLoadedMetadata = function () {
Expand Down
2 changes: 1 addition & 1 deletion js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ ImprovedTube.playerAutofullscreen = function () {
QUALITY
------------------------------------------------------------------------------*/
ImprovedTube.playerQuality = function (quality) {
if (!quality) var quality = this.storage.player_quality;
if (!quality) quality = this.storage.player_quality;
if (quality && quality !== 'auto') {
var player = this.elements.player;
if (player && player.getAvailableQualityLevels && !player.dataset.defaultQuality) {
Expand Down

0 comments on commit 62a36d2

Please sign in to comment.