Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Audio Player does not play url audio (OSStatus error 2003334207.)

$
0
0

I have a video player that works when I capture audio recordings locally and store them in a location on the device. When I try to upload the audio recording to firestore the audio is correctly uploaded and I can paste the link into google to listen to the correct audio file. However when I try to use the same audio player to play the audio with firestore's link then I get the error below. I tried adding ".m4a" extension to the URL and removing it but I keep getting the same error.

Playback failed.The operation couldn’t be completed. (OSStatus error 2003334207.)

Working URL's

https://firebasestorage.googleapis.com:443/v0/b/hustle-85b6c.appspot.com/o/audio%2F60787BCB-DEFE-4743-BF05-A2EAF24C0F28.m4a?alt=media&token=a29c8a9a-ce16-4240-9af1-5aefcac8a824.m4a

https://firebasestorage.googleapis.com:443/v0/b/hustle-85b6c.appspot.com/o/audio%2F60787BCB-DEFE-4743-BF05-A2EAF24C0F28.m4a?alt=media&token=a29c8a9a-ce16-4240-9af1-5aefcac8a824

audio player

import SwiftUIimport AVFoundationpublic final class AudioPlayer: NSObject, ObservableObject, AVAudioPlayerDelegate {    @Published public var soundSamples: [SampleModel] = []    @Published public var isPlaying = false    var audioPlayer = AVAudioPlayer()    private var timer: Timer?    private var currentSample: Float = 0    private let numberOfSamples: Int    private var durationTimer: Timer?    var fileDuration: TimeInterval = 0    var currentTime: Int = 0    static let shared = AudioPlayer(numberOfSamples: 15)    public init(isPlaying: Bool = false, audioPlayer: AVAudioPlayer = AVAudioPlayer(), timer: Timer? = nil, numberOfSamples: Int) {        self.isPlaying = isPlaying        self.audioPlayer = audioPlayer        self.timer = timer        self.numberOfSamples = numberOfSamples    }    func playSystemSound(soundID: SystemSoundID) {        AudioServicesPlaySystemSound(soundID)    }    func startPlayback(audio: URL) {        let original = audio.absoluteString        print(original)        let updatedURL = original +".m4a"        print(updatedURL)        do {            try AVAudioSession.sharedInstance().setCategory(.playback, options: .duckOthers)            try AVAudioSession.sharedInstance().setActive(true)            audioPlayer = try AVAudioPlayer(contentsOf: URL(string: updatedURL)!)            audioPlayer.volume = 1.0            audioPlayer.delegate = self            audioPlayer.play()            withAnimation {                isPlaying = true            }            fileDuration = audioPlayer.duration.rounded()            startMonitoring()        } catch let error {            print("Playback failed.\(error.localizedDescription)")        }    }    func startMonitoring() {        audioPlayer.isMeteringEnabled = true        currentTime = Int(fileDuration)        timer = Timer.scheduledTimer(withTimeInterval: 0.03, repeats: true) { [weak self] _ in            guard let this = self else { return }            this.audioPlayer.updateMeters()            this.currentSample = this.audioPlayer.peakPower(forChannel: 0)            this.soundSamples.append(SampleModel(sample: this.currentSample))        }        durationTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in            guard let this = self else { return }            this.currentTime -= 1        }    }    private func stopMonitoring() {        soundSamples = []        audioPlayer.isMeteringEnabled = false        timer?.invalidate()        durationTimer?.invalidate()        currentTime = Int(fileDuration)    }    public func stopPlayback() {        audioPlayer.stop()        stopMonitoring()        withAnimation {            isPlaying = false        }    }    public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {        if flag {            stopPlayback()        }    }}

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>