Skip to content

Commit

Permalink
Add usePlayerObjectFit option
Browse files Browse the repository at this point in the history
Only consider `object-fit` CSS property when selecting playlists based
on play size when `usePlayerObjectFit` option is `true` to make new
behavior an opt-in.
  • Loading branch information
tf committed Jan 17, 2024
1 parent caf9ba6 commit c6ea01a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Video.js Compatibility: 7.x, 8.x
- [enableLowInitialPlaylist](#enablelowinitialplaylist)
- [limitRenditionByPlayerDimensions](#limitrenditionbyplayerdimensions)
- [useDevicePixelRatio](#usedevicepixelratio)
- [usePlayerObjectFit](#useplayerobjectfit)
- [allowSeeksWithinUnsafeLiveWindow](#allowseekswithinunsafelivewindow)
- [customTagParsers](#customtagparsers)
- [customTagMappers](#customtagmappers)
Expand Down Expand Up @@ -404,6 +405,15 @@ This setting is `true` by default.
If true, this will take the device pixel ratio into account when doing rendition switching. This means that if you have a player with the width of `540px` in a high density display with a device pixel ratio of 2, a rendition of `1080p` will be allowed.
This setting is `false` by default.

##### usePlayerObjectFit
* Type: `boolean`
* can be used as an initialization option.

If true, the video element's `object-fit` CSS property will be taken
into account when doing rendition switching. This ensures that a
suitable rendition is selected for videos that are scaled up to cover
the media element. This setting is `false` by default.

##### allowSeeksWithinUnsafeLiveWindow
* Type: `boolean`
* can be used as a source option
Expand Down
4 changes: 2 additions & 2 deletions src/playlist-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export const lastBandwidthSelector = function() {
bandwidth: this.systemBandwidth,
playerWidth: parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10) * pixelRatio,
playerHeight: parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10) * pixelRatio,
playerObjectFit: safeGetComputedStyle(this.tech_.el(), 'objectFit'),
playerObjectFit: this.usePlayerObjectFit ? safeGetComputedStyle(this.tech_.el(), 'objectFit') : '',
limitRenditionByPlayerDimensions: this.limitRenditionByPlayerDimensions,
playlistController: this.playlistController_
});
Expand Down Expand Up @@ -442,7 +442,7 @@ export const movingAverageBandwidthSelector = function(decay) {
bandwidth: average,
playerWidth: parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10) * pixelRatio,
playerHeight: parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10) * pixelRatio,
playerObjectFit: safeGetComputedStyle(this.tech_.el(), 'objectFit'),
playerObjectFit: this.usePlayerObjectFit ? safeGetComputedStyle(this.tech_.el(), 'objectFit') : '',
limitRenditionByPlayerDimensions: this.limitRenditionByPlayerDimensions,
playlistController: this.playlistController_
});
Expand Down
3 changes: 3 additions & 0 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ class VhsHandler extends Component {
this.options_.withCredentials = this.options_.withCredentials || false;
this.options_.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions === false ? false : true;
this.options_.useDevicePixelRatio = this.options_.useDevicePixelRatio || false;
this.options_.usePlayerObjectFit = this.options_.usePlayerObjectFit || false;
this.options_.useBandwidthFromLocalStorage =
typeof this.source_.useBandwidthFromLocalStorage !== 'undefined' ?
this.source_.useBandwidthFromLocalStorage :
Expand Down Expand Up @@ -738,6 +739,7 @@ class VhsHandler extends Component {
[
'withCredentials',
'useDevicePixelRatio',
'usePlayerObjectFit',
'limitRenditionByPlayerDimensions',
'bandwidth',
'customTagParsers',
Expand All @@ -761,6 +763,7 @@ class VhsHandler extends Component {

this.limitRenditionByPlayerDimensions = this.options_.limitRenditionByPlayerDimensions;
this.useDevicePixelRatio = this.options_.useDevicePixelRatio;
this.usePlayerObjectFit = this.options_.usePlayerObjectFit;
}
// alias for public method to set options
setOptions(options = {}) {
Expand Down
5 changes: 5 additions & 0 deletions test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const options = [{
default: false,
test: true,
alt: false
}, {
name: 'usePlayerObjectFit',
default: false,
test: true,
alt: false
}, {
name: 'bandwidth',
default: 4194304,
Expand Down

0 comments on commit c6ea01a

Please sign in to comment.