如何在我的ios App中嵌入youtube或facebook直播? [英] how to embed youtube or facebook live streaming in my ios App ?

查看:633
本文介绍了如何在我的ios App中嵌入youtube或facebook直播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找IOS的facebook SDK,但我无法得到一个可靠的答案。所以我在这里问,天气是否有可能使用swift在我的IOS应用程序中传输实时facebook视频或youtube视频?如果是,那么随时给我一些提示或分享好读和引用
Tnx

I have been looking over facebook SDK for IOS but I could not really get a solid answer . So I am asking here , weather is it possible to stream the live facebook video or youtube video in my IOS app using swift ? if yes , then feel free to give me some tips or share good reads and references Tnx

推荐答案

嵌入youtube直播到您的iOS应用程序使用以下内容:

To embed youtube live stream onto your iOS app use the following:

   @IBOutlet weak var LiveStreamViewer: UIWebView!
   let channelID = "[channelID]"

   func loadLiveStream {
        guard
            let youtubeURL = URL(string: "https://www.youtube.com/embed?
                live=1&channel=\(channelID)")
            else { return }
        LiveStreamViewer.loadRequest( URLRequest(url: youtubeURL) )
   }

但是,如果你实际上没有流式传输,并且有人试图玩,那么使用它会在WebView中出现错误视频。为了计划添加类似于以下功能的东西:

However, using this will bring up an error within the WebView if you are not actually streaming, and someone tries to play the video. To plan for that add something similar to the following function:

   let googleAPI = "[youtubeAPIKey]"


   func checkLive() {
       let liveChannel = URL(string: "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=\(channelID)&type=video&eventType=live&key=\(googleAPI)")
       URLSession.shared.dataTask(with:liveChannel!, completionHandler: {(data, response, error) in
           guard let data = data, error == nil else { return }

           do {
               let parsedData = try JSONSerialization.jsonObject(with: data, options: []) as! [String:Any]
               let pageInfo = parsedData["pageInfo"] as! [String:Any]

               print(pageInfo)

               let currentState = pageInfo["totalResults"] as! Int
               print(currentState)

               if currentState == 0 {
                   print("No Stream Right Now")
                   self.LiveStreamViewer.isHidden = true
                   //DO SOMETHING TO LET THEM KNOW YOU ARENT STREAMING
               } else {
                   print("Streaming")
                   self.LiveStreamViewer.isHidden = false
                   self.loadLiveStream()
               }

           } catch let error as NSError {
               print(error)
           }
       }).resume()
   }

这篇关于如何在我的ios App中嵌入youtube或facebook直播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆