ios - 在 UItableView 单元格中快速播放视频

标签 ios swift

我正在尝试在 TableView Cell 中播放视频。我正在使用这段代码,但是当我运行时什么也不会出现。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "myCell")!
    let videoURL = NSURL(string: "http://techslides.com/demos/sample-videos/small.mp4")
    let player = AVPlayer(url: videoURL! as URL)
    let playerLayer = AVPlayerLayer(player: player)

    playerLayer.frame = myCell.bounds
    myCell.layer.addSublayer(playerLayer)
    player.play()

    return myCell
}

最佳答案

根据我之前的评论,请在 info.plist 中启用应用程序传输安全。

以下是直观的设置:

enter image description here

关于ios - 在 UItableView 单元格中快速播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40391699/

相关文章:

swift - 如何解决 NSAppleMusicUsageDescription 错误

objective-c - iOS DropboxSDK,获取远程子目录和内容

ios - 搜索栏结果未显示在表格 View 中

ios - 如何指定WKWebView请求的超时间隔?

swift - addPersistentStoreWithType 到底在做什么?

swift - 使用 Swift JSONEncoder 编码时会发生什么错误

Swift2,在 CFSocketCallBack 中调用 swift 函数 - EXEC_BAD_ACCESS

ios - 在 'passwordRules' 类型的对象上找不到属性 'UIView<RCTBackedTextInputViewProtocol> *'

ios - 带有单独数据源对象的 UITableViewController

objective-c - iOS UITextView - setText 方法不显示我的文本?