WKWEbView 在 iOS 中隐藏本机播放器的控件

Mat*_*ios 5 embed youtube wkwebview

我正在我的 iOS 应用程序中复制 Youtube 视频。我面临的问题是当视频播放时,它会在 iOS 的本机视频播放器中播放。

这对我来说没问题,但我想禁用本机播放器中的控件,以便用户无法跳过视频。

这可能吗?

这是我的代码:

func setUpUI() {
        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.allowsInlineMediaPlayback = true
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        webView.backgroundColor = .red 
        self.backgroundColor = .white
        webView.translatesAutoresizingMaskIntoConstraints = false
        self.contentView.addSubview(mainContainer)
        mainContainer.addSubview(lineSeparator)
        mainContainer.addSubview(bottomLineSeparator)
        mainContainer.addSubview(videoIcon)
        mainContainer.addSubview(watchItAll)
        mainContainer.addSubview(videoContainer)
        videoContainer.addSubview(videoTitleContainer)
        videoContainer.addSubview(webView)
        videoTitleContainer.addSubview(videoTitleLabel)

        lineSeparator.backgroundColor = .lightGreyBkgrnd
        lineSeparator.layer.borderColor = UIColor.lightGreyBkgrnd.cgColor
        lineSeparator.layer.borderWidth = 3

        videoContainer.layer.borderColor = UIColor.dimGray.cgColor
        videoContainer.layer.borderWidth = 2

        bottomLineSeparator.backgroundColor = .lightGreyBkgrnd
        bottomLineSeparator.layer.borderColor = UIColor.lightGreyBkgrnd.cgColor
        bottomLineSeparator.layer.borderWidth = 3

        self.videoTitleLabel.font = UIFont.preferredFont(forTextStyle: .headline)
        self.videoTitleLabel.textColor = UIColor.tuftsBlue

        videoPlayerSuperView.translatesAutoresizingMaskIntoConstraints = false
        self.watchItAll.font = UIFont.preferredFont(forTextStyle: .body)
        self.watchItAll.numberOfLines = 0

        //videoContainer.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(videoTapped)))

        let html = """
        <iframe width="100%" height="100%" src="https://www.youtube.com/embed/0oBx7Jg4m-o?autoplay=0&showinfo&controls=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        """
        webView.loadHTMLString(html, baseURL: nil)
    }
Run Code Online (Sandbox Code Playgroud)

cor*_*ora 0

如果您使用 AVPlayerViewController 来播放视频,它有一个属性

open var showsPlaybackControlls: Bool
Run Code Online (Sandbox Code Playgroud)

您可以将其设置为“否”以隐藏用户控件。

此外,如果您突出显示该类并选择“转到定义”,您将看到您可能想要决定使用的该类的其他函数和属性。