Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Domain=NSOSStatusErrorDomain Code=1954115647 "(null)"

Tags:

ios

swift

So I have an AVAudioPlayer, sometimes it works great, but sometimes it prints the error "Error Domain=NSOSStatusErrorDomain Code=1954115647 "(null)"". Here is the code:

override func viewDidLoad() {
    super.viewDidLoad()
    downloadFileFromURL(url: URL(string: mainPreviewURL)!)
}

func downloadFileFromURL(url: URL) {
    var downloadTask = URLSessionDownloadTask()
    downloadTask = URLSession.shared.downloadTask(with: url, completionHandler: {
        customURL, response, error in

        self.play(url: customURL!)
    })
    downloadTask.resume()
}

func play(url: URL) {
    do {
        player = try AVAudioPlayer(contentsOf: url)
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        player!.prepareToPlay()
        player!.play()
    } catch {
        print(error)
    }
}
like image 764
Toma Avatar asked Feb 01 '17 13:02

Toma


2 Answers

Make the code in your do statement look like this:

    let songData = try NSData(contentsOfURL: songURL!, options: NSDataReadingOptions.mappedIfSafe)
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
    try AVAudioSession.sharedInstance().setActive(true)
    player = try AVAudioPlayer(data: songData!, fileTypeHint: AVFileTypeMpegLayer3)
    player!.prepareToPlay()
    player!.play()
like image 188
Timmy Avatar answered Sep 28 '22 07:09

Timmy


When you have this kind of error code usually your audio files are not recognized by Xcode / OS or corrupted. To verify this step, you can select one of your audio file and try to playing it inside Xcode:

enter image description here

If you have , instead of this picture, the total absence of your media player like this image:

enter image description here

probably you should fix your audio files. I checked it and I've seen that sometimes it happened when you use versioning operation system like GIT (git merging, pulling from other systems..) or when you made copies of your files to another system. BUT you should remember that High Sierra can play FLAC's audio from the FINDER preview instead of Sierra, so your issue could be related simply to your current OS.

Solution: remove and restore the original audio file/files version. If you try to use it in a simulator running to Sierra you could continue to have this issue, make your tries to High Sierra and see what happened.

like image 36
Alessandro Ornano Avatar answered Sep 28 '22 06:09

Alessandro Ornano