How to Download Video Urlstring from Firebase Database Not Storage in Swift

Can't download a picture url from FirebaseStorage to FirebaseDatabase - Swift - metadata.downloadURL() not recognized anymore

This is the way I managed to solve my own question!

 @IBAction func postButtonPressed(_ sender: Any) {

let storage = Storage.storage()
let storageRef = storage.reference()
let photoIdString = "\(NSUUID().uuidString).jpg"
let imageReference = storageRef.child("posts").child(photoIdString)
if let imageData = UIImageJPEGRepresentation(selectedImage, 0.7) {
imageReference.putData(imageData).observe(.success) { (snapshot) in
imageReference.downloadURL(completion: { (url, error) in

if let downloadUrl = url {

let directoryURL : NSURL = downloadUrl as NSURL
let urlString:String = directoryURL.absoluteString!
self.sendDataToDatabase(photoUrl: urlString)
}
else {
print("couldn't get profile image url")
return
}
})}

Quick note sendDataToDatabase is a function I have where I use the my setValue method to send the data to Firebase.

Unable to play firebase video on my iOS device

Guys no problem in my player code as I have test another video like test.mov file and its working in both solution.

  • Live streaming
  • Local file

So I found one answer here which help me to test my video formate.

Answer by Mike McDonald:

I have a feeling that the issue here is that the video is not in the
correct format (needs to be H.264 or MPEG-4 in .mp4, .m4v, .mov [or an
HLS video for live streaming]), and the content type should be set
appropriately (video/mp4, video/x-m4v, video/quicktime). Can you
confirm these?

Still for my satisfaction I have tried this video on Mac quick time player and got below error.

Sample Image

Than I realised that some time due to video formate we unable to play or stream video.

Thanks every one who helped here.

This answer is for whom who is facing same issue like me.

how to detect if Firebase url is Photo or Video - Swift

You can simply initialize an url with your link and get the path extension:

let link1 = "https://firebasestorage.googleapis.com/v0/b/myApp-1e48d.appspot.com/o/Images%2FD118DA58-C128-4E5E-BF24-AA820BEE5590.jpg?alt=media&token=49eie236-f9d1-45f8-bd0b-887382c61ccd"

if let url = URL(string: link1) {
let fileType = url.pathExtension // "jpg"
}

let link2 = "https://firebasestorage.googleapis.com/v0/b/myApp-1e48d.appspot.com/o/Videos%2F1E4B7CA0-4D0E-4AC5-9856-2F59D0811C47.mp4?alt=media&token=615teacf-0d20-48aa-bb8f-cew84a14d76d"

if let url = URL(string: link2) {
let fileType = url.pathExtension // "mp4"
}


Related Topics



Leave a reply



Submit