0

I've been banging my head on the wall with this one for a while.

I have a videoPlayer, embedded in a zStack, embedded in a scrollview.

The videoPlayer stays at a static 9:16 aspect ratio, always. When I import a video that is more landscape, say with an aspect ratio of 16:9, using ".scaleToFill" on the player will scale the player up to a square, but won't scale all the way to fill the videoPlayer. The videoPlayer always remains a square, and will not scale past the height of the frame. I would like for the video to scale all the way up, so that there are no black bars on the top and bottom. See attached image.

I've tried messing with the player and the playerLayer video gravity, with no luck.

Thank you for the help.

My videoplayer:

var body: some View {
    
    GeometryReader { geometry in
        
        let frameWidth: CGFloat = geometry.size.width
        let frameHeight: CGFloat = geometry.size.width * 16 / 9
        
        VideoPlayer(player: VideoPlayerManagerVM.player)
            .aspectRatio(16/9, contentMode: .fill)
            .scaledToFill()
            .ignoresSafeArea()
            .disabled(true)
            .frame(width: frameWidth, height: frameHeight)
    }
}

My container

var body: some View {
    ZStack {
        ZStack {
            videoPlayerEditor()
            ForEach(Array($clipArray.textOverlayArray.enumerated()), id: \.element.id) { index, item in
                VideoText(
                    id: item.id,
                    index: .constant(index),
                    textPosition: item.textPosition.wrappedValue,
                    textRotation: item.textRotation.wrappedValue,
                    textColor: item.textColor.wrappedValue,
                    overlayText: item.text.wrappedValue,
                    textFieldWidth: item.textFieldWidth.wrappedValue,
                    tapAction: tapAction,
                    submitAction: submitAction,
                    deleteAction: deleteAction
                )
            }
        }
        
        ZStack {
            Rectangle()
                .fill(Color("grey-2"))
            ProgressView()
        }
        .opacity(PostBasicsVM.isTimelineLoading ? 1 : 0)
    }
    .clipped()
    .cornerRadius(12)
    .overlay(RoundedRectangle(cornerRadius: 12)
        .inset(by: globalRef.strokeWidth)
        .stroke(Color("grey-5"), lineWidth: globalRef.strokeWidth))
    
}

And then all of this is embedded in a scrollview.

current video scaling behavior

0

Browse other questions tagged or ask your own question.