I have 3 types of video:
How to select automatically quality of video depending on network throughput of the user?
Step 1
Upload an image around size of 1Mb somewhere on your server. You must know exact size of image in bytes and image's URL.
Step 2
var imageAddr = "IMAGE_URL_HERE";
imageAddr += "?n="+Math.random();
var startTime, endTime;
var downloadSize = SIZE_OF_IMAGE_IN_BYTES;
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
showResults();
}
startTime = (new Date()).getTime();
download.src = imageAddr;
function showResults() {
var duration = (endTime - startTime) / 1000; //Math.round()
var bitsLoaded = downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
if(speedMbps<1){
//LOAD_SMALL_VIDEO
}
else if(speedMbps<2){
//LOAD_MEDIUM_VIDEO
}
else {
//LOAD_LARGE_VIDEO
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With