1
我已經直接在firebase存儲中上傳了一些歌曲,我只是想在AVAudioPlayer中播放歌曲。 下面是我試圖代碼:通過firebase的音頻流
var mainRef : FIRStorageReference{
return FIRStorage.storage().reference(forURL: "gs://musicapp-d840c.appspot.com")
}
var audioStorageRef : FIRStorageReference{
return mainRef.child("SongsPath")
}
audioStorageRef.downloadURL { url, error in
if let error = error {
print(error.localizedDescription)
} else {
if let url = url{
do {
self.audioPlayer = try AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: String(describing: url)) as URL)
self.audioPlayer.play()
}
catch {
}
let storyboard = UIStoryboard(name: "AudioPlayer", bundle: nil)
let audioVc = storyboard.instantiateViewController(withIdentifier: "AudioPlayerViewController") as! AudioPlayerViewController
audioVc.playThisSong = String(describing: url)
self.present(audioVc, animated: false, completion: nil)
}
}
}
這裏從firebase
歌曲的URL被傳遞,但它跳過self.audioPlayer.play
。 ,我只想流式傳輸音頻。我能爲此獲得適當的解決方案嗎?