SwiftUI - tvOS 上的 AVPlayerViewController 全屏

SwiftUI - AVPlayerViewController Full Screen on tvOS

我可以通过 SwiftUI 显示 AVPlayerViewController,但视频周围有一些填充,我希望它是全屏的。

SwiftUI 部分有以下内容:

    var body: some View {
    NavigationView {
        List {
            ForEach(topicsArray) { topic in
                Section(header: Text(topic.title)) {
                    ForEach(0..<topic.shows.count) { index in
                        NavigationLink(destination: PlayerView(showID: topic.shows[index])) {
                            ShowCell(showID: topic.shows[index])
                        }
                        .navigationBarTitle("")
                        .navigationBarHidden(true)
                    }
                }
            }
        }
        .listStyle(GroupedListStyle())
        .padding()
    }.onAppear(perform: initialDataLoad)
}

从显示玩家的 NavigationLink 调用的代码是:

    struct PlayerView: UIViewControllerRepresentable {
       var showID:Int

       func makeUIViewController(context: Context) -> AVPlayerViewController {
           let pv = PlayerViewController()
           pv.showID = showID
           return pv
       }

       func updateUIViewController(_ viewController: AVPlayerViewController, context: Context) {

       }
   }

class PlayerViewController: AVPlayerViewController {
    var showID:Int! {
        didSet {
            setup()
        }
    }
    private var videoLaunch:VideoLaunch!

    private func setup() {
        videoLaunch = VideoLaunch(showID: showID,
                                  season: nil,
                                  episodeID: nil,
                                  selectedIndex: IndexPath(row: 0, section: 0),
                                  showType: .single,
                                  dataStructure: topics as Any,
                                  screenType: .live)

        playVideo()
    }

    private func playVideo() {
        guard let videoURL = self.videoLaunch.getMediaURL() else {print("Problem getting media URL");return}
        self.player = AVPlayer(url: videoURL)
        self.videoGravity = .resizeAspectFill
        self.player?.play()
    }

我试过设置边界并使用 modalpresentationstyle 全屏,但 none 有任何影响。视频周围仍然有看起来像 10 点的边框。

我能够通过在 PlayerViewController class.

中插入以下内容来解决问题
    override func viewDidLayoutSubviews() {
       self.view.bounds = UIScreen.main.bounds
    }