I have been looking everywhere for how to get a videos URLString
out of Firebase tree structure but can’t find it anywhere. Everything seems to be showing only how to play directly from Firebase Storage. I have already created a URLString
in a tree node in Firebase Database which points to a video in Storage. I’m trying to get the urlString
of highlightVideo
from that tree.
Here’s where I’m up to with the code:
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()
}}