Files
VibeCoding/webrtc_controller_ios/web_rtc_controller_ios/Views/SelfCodecDisplayView.swift
TongTongStudio 376a2c1217 fix: 修复视频画面拉伸变形问题
移除视频预览层的aspectRatio约束,并将本地解码画面渲染模式从resizeAspect改为resizeAspectFill,确保视频内容正确填充显示区域。
2026-08-01 04:09:14 +08:00

40 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import UIKit
import SwiftUI
import AVFoundation
/// UIKit AVSampleBufferDisplayLayer backing layer
/// "" H.264 Android SurfaceView
final class SampleBufferDisplayView: UIView {
override class var layerClass: AnyClass {
AVSampleBufferDisplayLayer.self
}
var sampleBufferLayer: AVSampleBufferDisplayLayer {
layer as! AVSampleBufferDisplayLayer
}
override init(frame: CGRect) {
super.init(frame: frame)
sampleBufferLayer.videoGravity = .resizeAspectFill
backgroundColor = .black
}
required init?(coder: NSCoder) {
super.init(coder: coder)
sampleBufferLayer.videoGravity = .resizeAspectFill
backgroundColor = .black
}
}
/// SwiftUI
struct SelfCodecDisplayViewRepresentable: UIViewRepresentable {
let view: SampleBufferDisplayView
func makeUIView(context: Context) -> SampleBufferDisplayView {
view
}
func updateUIView(_ uiView: SampleBufferDisplayView, context: Context) {}
}