Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 4138
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 3, 20222022-06-03T13:03:06+00:00 2022-06-03T13:03:06+00:00

javascript – how to find styling of a video tag to keep it from getting cropped

  • 0

[ad_1]

It’s a really complex situation. I have a parent div which contains video tag wrapped in another div.
Parent div can keep on changing is aspect ratio. Like it can sometime act as portrait div and sometimes as landscape div.
Now I have to find out what styling (height:100% or width: 100%} i can apply to the video tag (which will be wrapped around another div for a specific reason) so that it work as the video is contained in the parent div (do not get cropped)
(I know object-fit. property exists that can do that) but i there is a catch, If i use that than i don’t get the actual box of the video that is playing. I also get the black stripes. I want to keep a label inside the video that is playing (which is why im wrapping video tag in another div which contains that label and that label is positioned as absolute)

Now this is working and i run this on every layout change (there are multiple boxes) but it glitches and is not that good. So i was looking if anyone else has a better idea.

** Basically what i want to do is show a video inside a varying container and i want to show a label inside the video that is playing and also keeps the video from getting cropped. **

const handleCrop = (_crop, _index, _data) => {
    if (!videoContainerRef?.current) return;
    if (!stream?.getTracks()[data.streamType === 'screen' ? 0 : 1]?.getSettings()) return;
    let videoRatio = stream
      .getTracks()
      [data.streamType === 'screen' ? 0 : 1].getSettings().aspectRatio;
    videoRatio = parseFloat(videoRatio).toFixed(2);
    const { height: containerHeight, width: containerWidth } =
      videoContainerRef.current.getBoundingClientRect();
    const containerRatio = parseFloat(containerWidth / containerHeight).toFixed(2);
    if (_crop >= 0.5) {
      if (containerRatio > videoRatio) setCroppingStyle({ width: '100%' });
      else setCroppingStyle({ height: '100%' });
    } else {
      if (containerRatio >= videoRatio) {
        setCroppingStyle({ height: '100%' });
      } else setCroppingStyle({ width: '100%' });
    }
  };

<div
    id={`participant-${index}-video-container-id`}
          className={`position-absolute d-flex align-item-center justify-content-center ${
            !data?.video || data?.selfMute?.video ? 'full-height full-width' : ''
          }`}
          style={croppingStyle}
        >
          <ParticipantLabel
            index={index}
            data={data}
            label={label}
            labelStyle={labelStyle}
            layout={layout}
            participant={participant}
            ratio={ratio}
            showLabel={showLabel}
            handleSpotlight={handleSpotlight}
          />
          <video
            id={`participant-video-${index}`}
            ref={videoRef}
            className={` ${
              userId === data.id && data.streamType === 'camera' && setting?.video?.mirrored
                ? 'invert-x'
                : ''
            }`}
            style={{ ...croppingStyle, objectFit: 'cover' }}
            muted={true}
            controls={false}
            autoPlay={true}
          >
            Your browser does not support HTML video.
            <audio
              id={`participant-audio-${index}`}
              className={'invisible'}
              ref={audioRef}
              autoPlay={true}
            />
          </video>
          {noImage}
        </div>
 <div
          id={`participant-${index}-video-container-id`}
          className={`position-absolute d-flex align-item-center justify-content-center ${
            !data?.video || data?.selfMute?.video ? 'full-height full-width' : ''
          }`}
          style={croppingStyle}
        >
          <ParticipantLabel
            index={index}
            data={data}
            label={label}
            labelStyle={labelStyle}
            layout={layout}
            participant={participant}
            ratio={ratio}
            showLabel={showLabel}
            handleSpotlight={handleSpotlight}
          />
          <video
            id={`participant-video-${index}`}
            ref={videoRef}
            className={` ${
              userId === data.id && data.streamType === 'camera' && setting?.video?.mirrored
                ? 'invert-x'
                : ''
            }`}
            style={{ ...croppingStyle, objectFit: 'cover' }}
            muted={true}
            controls={false}
            autoPlay={true}
          >
            Your browser does not support HTML video.
            <audio
              id={`participant-audio-${index}`}
              className={'invisible'}
              ref={audioRef}
              autoPlay={true}
            />
          </video>
          {noImage}
        </div>
    

[ad_2]

  • 0 0 Answers
  • 21 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8038 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1840 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1920 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.