Problem
As the title says, I'm seeing an issue where the browser (when seeking through a video) is constantly making requests for ranges of bytes it should already have.
Code
I've provided a minimal code sample; to replicate the issue, whip around the current time control on the video and look at your network log.
window.onload = function() {
var myVideo = document.getElementById('my-video');
myVideo.addEventListener('progress', function() {
var bufferedEnd = myVideo.buffered.end(myVideo.buffered.length - 1);
var duration = myVideo.duration;
if (duration > 0) {
document.getElementById('buffered-amount').style.width = ((bufferedEnd / duration) * 100) + "%";
}
});
myVideo.addEventListener('timeupdate', function() {
var duration = myVideo.duration;
if (duration > 0) {
document.getElementById('progress-amount').style.width = ((myVideo.currentTime / duration) * 100) + "%";
}
});
}
.buffered {
height: 20px;
position: relative;
background: #555;
width: 300px;
}
#buffered-amount {
display: block;
height: 100%;
background-color: #777;
width: 0;
}
.progress {
margin-top: -20px;
height: 20px;
position: relative;
width: 300px;
}
#progress-amount {
display: block;
height: 100%;
background-color: #595;
width: 0;
}
<video id="my-video" controls preload="auto"><source src="https://media-dev.ozone.tech/media/045728df-7431-4548-8353-318357cc2643/video_preview-1655322764.5499873.mp4?Expires=1656287999&Signature=3RnkLu03JreuUZk9bICqqC5IwGiq~tWpBCaUSfyGb9W9VLPfw6Na4zh~tDTxxDjIirhocj7es2T0ONm0L6XsuFxsCx2T9-CANok014Kt6ddHEaUmuOi5uztEWyXpLmI3ussq4dc5lW2Xw5WH6uV-5Z8fIlIQehMxQK-XQ6RpdHhWBQLsmfPBqSSPnDk6KH5fkK-xCwQmxUwAN1nRVH8H6p~43~E6MZa7gSS~i1717~FlHto3depk~AvREjm59T1rNBvaZeb6ZI-pnYAf52wwQs3pWXln7PCtiIOYQCxE10l4nkOvJ--KGmPA0jOeSuv0dCRUi3QLZD5JxsJgBVM4sA__&Key-Pair-Id=K16V0JZ9ZAOTC6" type="video/mp4"></video>
<div class="buffered">
<span id="buffered-amount"></span>
</div>
<div class="progress">
<span id="progress-amount"></span>
</div>
Question
Can someone explain why this is happening and how I can prevent it? Seems like this could potentially be a bug but since all the browsers are doing it, I wonder if it's something on my end; maybe the way we encode the video?