Open MikeKoval opened 4 years ago
Looks like the youtube tech doesn't implement the videoHeight or videoWidth methods so a default value is being returned by Video.js.
@gkatsev Yeah, it seems, thinking why it might be missed to be implemented...
I was able to resolve my problem with reading .get(player, 'tech.ytPlayer.g.g.height') however I realize that at some moment "g" might be replaced to e. g. "b" in youtube api. I found that using "https://noembed.com/embed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dz_AbfPXTKms" might appear more reliable.
Looks like the API doesn't provide a way to know the size of the video being played. Best we could do is return the size of the iframe for this but that isn't really what videoHeight
and videoWidth
are supposed to represent.
I was just dealing with the same problem. I suspect, the problem is that the tech loads a protected iframe, and let the YouTube library take over. I found that tech.ytPlayer.g.g.height value is inconsistent and may not represent the actually dimension of the video. My solution was to force the desired height in the setting (assume 16:9 ration, which YouTube always uses), save the value somewhere in the player object, and create a wrapper function to return this value if videoHight() returns 0.
videojs(videoNode, options, function onPlayerReady() { this.on('loadedmetadata', () => { console.log( this.videoHeight()) // why it returns 0 always for youtube tech? }); });