ios - 无法在 Collection View 中播放 mp4 视频

标签 ios swift uiwebview

我正在尝试在 Collection View 中播放 mp4 视频,但未能成功。我试过的方法是:

方法一:

let html = "<video playsinline controls width=\"100%\" src=\"\(url)\"> </video>"
cell.webview.loadHTMLString(html, baseURL: nil)
cell.webview.allowsInlineMediaPlayback = true

方法二:

cell.webview.loadRequest(URLRequest(url: URL(string: source)!))

结果: Video doesn't load and shows this

最佳答案

你能试试下面的代码吗,

let html = "<video width=\"100%\" controls> <source src=\"http://test.creatrixcampus.com/uploads/doc/binaryOctalHex_1526459737.mp4\" type=\"video/mp4\"></video>"

更新

let html = "<iframe src=\"http://test.creatrixcampus.com/uploads/doc/binaryOctalHex_1526459737.mp4\" width=\"100%\"></iframe>"
webView.loadHTMLString(html, baseURL: nil)
webView.allowsInlineMediaPlayback = true

下面是相同的输出,

enter image description here

如有任何疑问,请告诉我。

关于ios - 无法在 Collection View 中播放 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50366118/

相关文章:

ios - 如何阻止 Xcode 静态分析器报告对象泄漏?

ios - Swift 2 JSON 字节数组到 UIImage

ios - 为 SKSpriteNode 的子类加载物理体

iphone - mobile safari 如何处理 pdf 以便提供搜索功能?

ios - UINavigationBar setHidden 之前的 WebView LoadRequest 为 YES

ios - SwiftUI 的 onAppear() 和 onDisappear() 在 Xcode 12.1 上多次调用且不一致

属性字符串的快速标题更改颜色保持默认蓝色

arrays - 从 swift 数组中删除每第 n 个元素

ios - UIWebview将不会在后台播放

ios - PDF小猫类似物