I am facing an issue with setting a video screen to 100% width and 100% height. On larger resolutions, the height does not display properly and gets cut off from view.
Even though the following aspect ratio works, it causes black bars on the left and right:
window.onresize = function(){
var aspectRatio;
if (remoteVideo.style.opacity === '1') {
aspectRatio = remoteVideo.videoWidth/remoteVideo.videoHeight;
} else if (localVideo.style.opacity === '1') {
aspectRatio = localVideo.videoWidth/localVideo.videoHeight;
} else {
return;
}
var innerHeight = this.innerHeight;
var innerWidth = this.innerWidth;
var videoWidth = innerWidth < aspectRatio * window.innerHeight ?
innerWidth : aspectRatio * window.innerHeight;
var videoHeight = innerHeight < window.innerWidth / aspectRatio ?
innerHeight : window.innerWidth / aspectRatio;
containerDiv = document.getElementById('container');
containerDiv.style.width = videoWidth + 'px';
containerDiv.style.height = videoHeight + 'px';
containerDiv.style.left = (innerWidth - videoWidth) / 2 + 'px';
containerDiv.style.top = (innerHeight - videoHeight) / 2 + 'px';
};
I have tried modifying the code but still face issues where increasing the width results in the height getting cut off. Even when using
webkitRequestFullScreen();
, the width and height do not render accurately.
window.onresize = function(){
var aspectRatio;
if (remoteVideo.style.opacity === '1') {
aspectRatio = remoteVideo.videoWidth/remoteVideo.videoHeight;
} else if (localVideo.style.opacity === '1') {
aspectRatio = localVideo.videoWidth/localVideo.videoHeight;
} else {
return;
}
var innerHeight = this.innerHeight;
var innerWidth = this.innerWidth;
var videoWidth = innerWidth < aspectRatio * window.innerHeight ?
innerWidth : aspectRatio * window.innerHeight;
var videoHeight = innerHeight < window.innerWidth / aspectRatio ?
innerHeight : window.innerWidth / aspectRatio;
containerDiv = document.getElementById('container');
//containerDiv.style.width = videoWidth + 'px';
containerDiv.style.width = window.innerWidth + 'px';
containerDiv.style.height = videoHeight + 'px';
//containerDiv.style.left = (innerWidth - videoWidth) / 2 + 'px';
//containerDiv.style.top = (innerHeight - videoHeight) / 2 + 'px';
};
The expected output should adjust correctly on resize, maximize, or full-screen:
If anyone has suggestions, please help as I am struggling to achieve the accurate expected output.