UIWebView 中嵌入的 YouTube 视频无法播放
Embedded YouTube video in a UIWebView fails to play
我想用 custom Cell
实现 UITableView
,它使用 UIWebView
,但我的问题是 UIWebView 不显示视频。我试着在一节课后复习https://w%20ww.youtube.com/watch?v=rcVv1N1hReQ,但这是不可能的。
Code
var testArray = ["https://www.youtube.com/embed/W7qWa52k-nE", "https://www.youtube.com/embed/vH7i-qpoFVk", "https://www.youtube.com/embed/V_GTrL-UVmE"]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! WebViewTableViewCell
cell.videoWeb.allowsInlineMediaPlayback = true
let embededHTML = "<html><body><iframe src=\"\(testArray[indexPath.row])?playsinline=1\" width=\"'\(cell.videoWeb.frame.width)'\" height=\"'\(cell.videoWeb.frame.height)'\" frameborder=\"10\" allowfullscreen></iframe></body></html>"
cell.videoWeb.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL)
cell.videoWeb.scrollView.scrollEnabled = false
return cell
}
Screenshot
Test Project
我想用 custom Cell
实现 UITableView
,它使用 UIWebView
,但我的问题是 UIWebView 不显示视频。我试着在一节课后复习https://w%20ww.youtube.com/watch?v=rcVv1N1hReQ,但这是不可能的。
Code
var testArray = ["https://www.youtube.com/embed/W7qWa52k-nE", "https://www.youtube.com/embed/vH7i-qpoFVk", "https://www.youtube.com/embed/V_GTrL-UVmE"]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! WebViewTableViewCell
cell.videoWeb.allowsInlineMediaPlayback = true
let embededHTML = "<html><body><iframe src=\"\(testArray[indexPath.row])?playsinline=1\" width=\"'\(cell.videoWeb.frame.width)'\" height=\"'\(cell.videoWeb.frame.height)'\" frameborder=\"10\" allowfullscreen></iframe></body></html>"
cell.videoWeb.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL)
cell.videoWeb.scrollView.scrollEnabled = false
return cell
}
Screenshot
Test Project