Reputation: 31
Here is my response:
Heritage Point1: [
Audio: "https://firebasestorage.googleapis.com/v0/b/sweetwalk-192506.appspot.com/o/Heritage%20Point1%2FAudios%2Fsmstreet1.mp3?alt=media&token=a3224b55-6039-4c6f-ac4e-78b9cf818c89"
CoverImage:"https://firebasestorage.googleapis.com/v0/b/sweetwalk-192506.appspot.com/o/Heritage%20Point1%2FImages%2Fsmstreet1.jpeg?alt=media&token=1acba6f0-8554-4b7e-828c-a7102c364d75"
Description: "none of the above"
]
Used AVFoundation Framework. I'm using Firebase, Xcode 9.2, Swift 4
Anyone please help me to play Audio from Firebase
Upvotes: 1
Views: 393
Reputation: 352
You can use following code:
let audioUrlStr = "https://firebasestorage.googleapis.com/v0/b/sweetwalk-192506.appspot.com/o/Heritage%20Point1%2FAudios%2Fsmstreet1.mp3?alt=media&token=a3224b55-6039-4c6f-ac4e-78b9cf818c89"
if let url = URL(string: audioUrlStr) {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
self.audioPlayer = try AVAudioPlayer(data: Data(contentsOf: url))
self.audioPlayer!.delegate = self
self.audioPlayer!.volume = 2.0
self.audioPlayer!.prepareToPlay()
print("Audio ready to play")
self.audioPlayer!.play()
} catch let error {
print("error occured while audio downloading")
print(error.localizedDescription)
}
}
Upvotes: 1