【问题标题】:WKWEbView Hide controls of native player in iOSWKWEbView 在 iOS 中隐藏原生播放器的控件
【发布时间】:2020-02-17 20:23:52
【问题描述】:

我正在我的 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)
    }

【问题讨论】:

    标签: youtube embed wkwebview


    【解决方案1】:

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

    open var showsPlaybackControlls: Bool
    

    您可以设置为 NO 以隐藏用户控件。

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

    【讨论】:

    • AVPlayer 不会复制 YouTube 视频。解决我的问题
    • 我已经编辑了我的问题并添加了相关代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 2015-01-05
    • 2017-05-04
    • 2012-02-14
    • 2017-11-28
    • 1970-01-01
    相关资源
    最近更新 更多