9c432427 by David LaPalomento

Use getComputedStyle for player dimensions when filtering variants. Closes #326

2 parents c2e40eba 310d41f1
...@@ -4,6 +4,7 @@ CHANGELOG ...@@ -4,6 +4,7 @@ CHANGELOG
4 ## HEAD (Unreleased) 4 ## HEAD (Unreleased)
5 * @dmlap improved video duration calculation. ([view](https://github.com/videojs/videojs-contrib-hls/pull/321)) 5 * @dmlap improved video duration calculation. ([view](https://github.com/videojs/videojs-contrib-hls/pull/321))
6 * Clamp seeks to the seekable range ([view](https://github.com/videojs/videojs-contrib-hls/pull/327)) 6 * Clamp seeks to the seekable range ([view](https://github.com/videojs/videojs-contrib-hls/pull/327))
7 * Use getComputedStyle for player dimensions when filtering variants ([view](https://github.com/videojs/videojs-contrib-hls/pull/326))
7 8
8 -------------------- 9 --------------------
9 10
......
...@@ -502,7 +502,9 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -502,7 +502,9 @@ videojs.Hls.prototype.selectPlaylist = function () {
502 oldvariant, 502 oldvariant,
503 bandwidthBestVariant, 503 bandwidthBestVariant,
504 resolutionPlusOne, 504 resolutionPlusOne,
505 resolutionBestVariant; 505 resolutionBestVariant,
506 playerWidth,
507 playerHeight;
506 508
507 sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth); 509 sortedPlaylists.sort(videojs.Hls.comparePlaylistBandwidth);
508 510
...@@ -538,6 +540,9 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -538,6 +540,9 @@ videojs.Hls.prototype.selectPlaylist = function () {
538 // (this could be the lowest bitrate rendition as we go through all of them above) 540 // (this could be the lowest bitrate rendition as we go through all of them above)
539 variant = null; 541 variant = null;
540 542
543 playerWidth = parseInt(getComputedStyle(player.el()).width, 10);
544 playerHeight = parseInt(getComputedStyle(player.el()).height, 10);
545
541 // iterate through the bandwidth-filtered playlists and find 546 // iterate through the bandwidth-filtered playlists and find
542 // best rendition by player dimension 547 // best rendition by player dimension
543 while (i--) { 548 while (i--) {
...@@ -555,14 +560,14 @@ videojs.Hls.prototype.selectPlaylist = function () { ...@@ -555,14 +560,14 @@ videojs.Hls.prototype.selectPlaylist = function () {
555 560
556 // since the playlists are sorted, the first variant that has 561 // since the playlists are sorted, the first variant that has
557 // dimensions less than or equal to the player size is the best 562 // dimensions less than or equal to the player size is the best
558 if (variant.attributes.RESOLUTION.width === player.width() && 563 if (variant.attributes.RESOLUTION.width === playerWidth &&
559 variant.attributes.RESOLUTION.height === player.height()) { 564 variant.attributes.RESOLUTION.height === playerHeight) {
560 // if we have the exact resolution as the player use it 565 // if we have the exact resolution as the player use it
561 resolutionPlusOne = null; 566 resolutionPlusOne = null;
562 resolutionBestVariant = variant; 567 resolutionBestVariant = variant;
563 break; 568 break;
564 } else if (variant.attributes.RESOLUTION.width < player.width() && 569 } else if (variant.attributes.RESOLUTION.width < playerWidth &&
565 variant.attributes.RESOLUTION.height < player.height()) { 570 variant.attributes.RESOLUTION.height < playerHeight) {
566 // if we don't have an exact match, see if we have a good higher quality variant to use 571 // if we don't have an exact match, see if we have a good higher quality variant to use
567 if (oldvariant && oldvariant.attributes && oldvariant.attributes.RESOLUTION && 572 if (oldvariant && oldvariant.attributes && oldvariant.attributes.RESOLUTION &&
568 oldvariant.attributes.RESOLUTION.width && oldvariant.attributes.RESOLUTION.height) { 573 oldvariant.attributes.RESOLUTION.width && oldvariant.attributes.RESOLUTION.height) {
......