swift - 如何从 Firebase 数据库而不是 Swift 中的存储下载视频 URLString

标签 swift firebase firebase-realtime-database firebase-storage

我一直在到处寻找如何从 Firebase 树结构中获取视频 URLString 但无法在任何地方找到它。一切似乎都只显示如何直接从 Firebase 存储播放。我已经在 Firebase 数据库的树节点中创建了一个 URLString,它指向存储中的一个视频。我正在尝试从该树中获取 highlightVideourlString

这是我要处理的代码:

 private func setupPlayerView() {

    FIRDatabase.database().reference().child("users").child(FIRAuth.auth()!.currentUser!.uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
        guard let dictionary = snapshot.value as? [String: String] else { return}

        let urlString = dictionary["highlightVideo"]
    }, withCancelBlock: nil)

    if let url = NSURL(string: urlString) { ---code breaks on urlstring
        player = AVPlayer(URL: url)

        let playerLayer = AVPlayerLayer(player: player)
        videoView.layer.addSublayer(playerLayer)
        playerLayer.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.width * (9/16))

        player?.play()
}}

最佳答案

我感觉这里的问题是视频的格式不正确(.mp4.m4v 中需要是 H.264 或 MPEG-4 code>, .mov [或用于直播的 HLS 视频]),内容类型应适当设置(video/mp4, video/x- m4v, video/quicktime).你能证实这些吗?

关于swift - 如何从 Firebase 数据库而不是 Swift 中的存储下载视频 URLString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40659732/

相关文章:

ios - 如何在 swift 3 中使用 HTTP Post 方法获取 JSON 数据?

ios - (Swift) 为键盘移动 View ?

ios - View 和 super View 之间的 NSSpace 属性必须匹配(自动布局)

将请求转发到 Cloud Functions 时 Firebase 托管自定义域 404

android - 如何升级 FirebaseListAdapter

javascript - Firebase http 将请求放在 for 循环中

ios - 更新由定时器驱动的函数中的变量

javascript - 创建计数器时 Firebase Cloud Functions onCreate 对象未定义

firebase - 如何在 Flutter 中将 onAuthStateChanged 用于 Firebase Auth?

firebase - ElasticSearch 排序给出 fielddata 错误