Embed youtube video in iOS App

后端 未结 2 1273
陌清茗
陌清茗 2021-01-03 02:42

I want to embed a youtube video into a webviewer whenever I press a button. I have this code

- (IBAction)testBtn:(id)sender {

    NSString *code = @\"

        
2条回答
  •  心在旅途
    2021-01-03 02:50

    you can add this code if you want to embed you tube video in swift

    let webViewYouTube = UIWebView()

        webViewYouTube.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.width/2)
    
        webViewYouTube.allowsInlineMediaPlayback = true
        webViewYouTube.mediaPlaybackRequiresUserAction = false
        webViewYouTube.mediaPlaybackAllowsAirPlay = true
        webViewYouTube.delegate = self as? UIWebViewDelegate
        webViewYouTube.scrollView.bounces = false
        webViewYouTube.scrollView.isScrollEnabled = false
        let linkObj = "https://www.youtube.com/watch?v=swIoyaBUpEg"
    
        print("linkObj1_________________\(linkObj)")
        let embedHTML = "        \\\\\\"
        let html = String(format: embedHTML, linkObj)
        webViewYouTube.loadHTMLString(html, baseURL: nil)
        view.addSubview(webViewYouTube)
    

提交回复
热议问题