@playkit-js/dynamic-watermark
Version:
kaltura-player-js dynamic watermark
24 lines (19 loc) • 568 B
text/typescript
export const observeVideoAspectRatio = (
video: HTMLVideoElement,
callback: (aspectRatio: number | null) => void,
) => {
const getAspectRatio = () => {
const aspectRatio = Math.max(0, video.videoWidth / video.videoHeight);
return isFinite(aspectRatio) ? aspectRatio : null;
};
const handleVideoResize = () => {
callback(getAspectRatio());
};
video.addEventListener('resize', handleVideoResize);
return {
initial: getAspectRatio(),
disconnect: () => {
video.removeEventListener('resize', handleVideoResize);
},
};
};