在UIWebView中播放Facebook视频 [英] Play facebook video in UIWebView
问题描述
有人知道如何在UIWebView
中播放Facebook视频吗?
Does anyone know how to play a facebook video in a UIWebView
?
我的应用程序将视频上传到Facebook,并检索视频的URL.我想将此URL嵌入到UIWebView
中进行播放.我已经为youtube而不是Facebook解决了这个问题.寻找帮助.
My app uploads video to facebook and retrieves the video's url. I'd like to embed this url into a UIWebView
to play back. I've worked this out for youtube but not Facebook. looking for help.
推荐答案
Orpheus!
我已经晚了几年,但是无论如何我都会在这里发布答案-自2018年起在Swift中;)以防万一有人需要它.
I’m a few years late lol, but I’ll post the answer here anyway -- in Swift since it’s 2018 ;) -- just in case someone needs it.
您可以使用以下HTML字符串:
You can use the following HTML string:
let embedCode = "<iframe src=\"https://www.facebook.com/plugins/video.php?href=\([INSERT VIDEO URL])&show_text=0&width=\(Int([INSERT WIDTH]))\" width=\"\(Int([INSERT WIDTH]))\" height=\"\(Int([INSERT WIDTH] * 56.25))\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" allowFullScreen=\"true\"></iframe>"
将[插入视频URL]替换为视频URL,将[插入宽度]替换为所需的Web视图宽度.
where you replace [INSERT VIDEO URL] with the video URL and [INSERT WIDTH] with the desired web view width.
然后将HTML加载到UIWebView
中,如下所示:
Then load the HTML into the UIWebView
like so:
webView.loadHTMLString(embedCode, baseURL: nil)
这篇关于在UIWebView中播放Facebook视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!