0
我是Swift的新手,我設法從firebase下載音頻並將其存儲在本地,但不知道如何使用AVAudioPlayer播放。任何幫助,將不勝感激。這是我到目前爲止。Swift 3播放從Firebase下載的音頻
class FireBaseViewController: UIViewController {
var audioPlayer:AVAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
let storageRef = FIRStorage.storage().reference()
let files = storageRef.child("Audio/Self Commitment.m4a")
let localURL: NSURL! = NSURL(fileURLWithPath:"/Users/wayne/Desktop/Playground/Audio/Self Commitment.m4a")
let downloadTask = files.write(toFile: localURL as URL) { (URL, error) -> Void in
if (error != nil) {
print("Uh-oh, an error occurred!")
} else {
print("Local file URL for is returned")
}
}
let audioPath = localURL
do {
try audioPlayer = AVAudioPlayer(contentsOf:URL(fileURLWithPath: audioPath))
} catch {print("file is unavilable")
}
audioPlayer.play()
}
}