Has any one had success storing an audio file in firebase storage, and then streaming that same file in IOS?
So far I've succesfully recorded the audio in swift (.m4a), upload the file to firebase storage, retrieved the download url which looks like this:
I stored that audio in my firebase DB, and imported it in a var called "stream" and attemped to pass that into the audio player with no luck...
I see some information on firestore supporting streaming for Andriod, but nothing related to IOS.
Anyone able to offer some help here? Do I need to use another service for storage to host streaming urls? Would love to launch my MVP only using firebase if possible.
@ObservedObject var audioPlayer = AudioPlayer()
var stream = ""
var body: some View {
VStack(alignment: .leading){
if audioPlayer.isPlaying == false {
Button(action: {
self.audioPlayer.startPlayback(audio: URL(string: self.stream)!)
}) {
Image(systemName: "play.circle")
.resizable()
.frame(width: 50, height: 50)
}
} else {
Button(action: {
self.audioPlayer.stopPlayback()
}) {
Image(systemName: "stop.fill")
.resizable()
.frame(width: 50, height: 50)
}
}
}
}
}
}
}
Full audio player for reference!
class AudioPlayer: NSObject, ObservableObject, AVAudioPlayerDelegate {
let objectWillChange = PassthroughSubject<AudioPlayer, Never>()
var isPlaying = false {
didSet {
objectWillChange.send(self)
}
}
var audioPlayer: AVAudioPlayer!
func startPlayback (audio: URL) {
let playbackSession = AVAudioSession.sharedInstance()
do {
try playbackSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch {
print("Playing over the device's speakers failed")
}
do {
audioPlayer = try AVAudioPlayer(contentsOf: audio)
audioPlayer.delegate = self
audioPlayer.play()
isPlaying = true
} catch {
print("Playback failed.")
}
}
func stopPlayback() {
audioPlayer.stop()
isPlaying = false
}
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
if flag {
isPlaying = false
}
}
}