@@ -59,6 +59,7 @@ export interface ReactPlayerBlockProps
5959 onClickPreview ?: ( ) => void ;
6060 height ?: number ;
6161 ratio ?: number ;
62+ autoRatio ?: boolean ;
6263 children ?: React . ReactNode ;
6364}
6465
@@ -87,6 +88,8 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
8788 height,
8889 ariaLabel,
8990 ratio,
91+ autoRatio,
92+ contain,
9093 } = props ;
9194
9295 const {
@@ -113,6 +116,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
113116 const [ playedPercent , setPlayedPercent ] = useState < number > ( 0 ) ;
114117 const [ currentHeight , setCurrentHeight ] = useState ( height ) ;
115118 const [ width , setWidth ] = useState < number > ( 0 ) ;
119+ const [ actualRatio , setActualRatio ] = useState < number > ( ) ;
116120 const [ muted , setMuted ] = useState < boolean > ( mute ) ;
117121 const [ started , setStarted ] = useState ( autoPlay ) ;
118122 const [ ended , setEnded ] = useState < boolean > ( false ) ;
@@ -202,7 +206,11 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
202206 parseFloat ( paddingRight ) ;
203207
204208 setWidth ( newWidth ) ;
205- setCurrentHeight ( Math . floor ( getHeight ( newWidth , ratio ) ) ) ;
209+ setCurrentHeight (
210+ Math . floor (
211+ getHeight ( newWidth , ratio ?? ( autoRatio ? actualRatio : undefined ) ) ,
212+ ) ,
213+ ) ;
206214 }
207215 } , 200 ) ;
208216
@@ -211,7 +219,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
211219 return ( ) => {
212220 window . removeEventListener ( 'resize' , updateSize ) ;
213221 } ;
214- } , [ ratio ] ) ;
222+ } , [ actualRatio , autoRatio , ratio ] ) ;
215223
216224 const playEvents = useMemo (
217225 ( ) => eventsArray ?. filter ( ( e : AnalyticsEvent ) => e . type === PredefinedEventTypes . Play ) ,
@@ -317,6 +325,16 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
317325 }
318326 } , [ changeMute , controls , customControlsType , ended , isPlaying , muted ] ) ;
319327
328+ const onReady = useCallback ( ( player : ReactPlayer ) => {
329+ setPlayerRef ( player ) ;
330+ const videoElement = player . getInternalPlayer ( ) ;
331+ const videoWidth = videoElement . videoWidth as number | undefined ;
332+ const videoHeight = videoElement . videoHeight as number | undefined ;
333+ if ( videoWidth && videoHeight ) {
334+ setActualRatio ( videoHeight / videoWidth ) ;
335+ }
336+ } , [ ] ) ;
337+
320338 const onProgress = useCallback ( ( progress : PlayerPropgress ) => {
321339 setPlayedPercent ( progress . played ) ;
322340
@@ -365,6 +383,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
365383 {
366384 wrapper : ! currentHeight ,
367385 controls,
386+ contain,
368387 } ,
369388 className ,
370389 ) }
@@ -390,7 +409,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
390409 progressInterval = { FPS }
391410 onClickPreview = { handleClickPreview }
392411 onStart = { onStart }
393- onReady = { setPlayerRef }
412+ onReady = { onReady }
394413 onPlay = { onPlay }
395414 onPause = {
396415 autoPlay && customControlsType !== CustomControlsType . WithMuteButton
0 commit comments