teodorpatras / Jukebox

Player for streaming local and remote audio files. Written in Swift.
MIT License
551 stars 122 forks source link

Validate assets shouldn't throw a fatal error when the asset returns a 404 #14

Closed samuelbeek closed 8 years ago

samuelbeek commented 8 years ago
   private func validateAsset(asset : AVURLAsset) {
        var e : NSError?
        asset.statusOfValueForKey("duration", error: &e)
        if let error = e {
            var message = "\n\n***** Jukebox fatal error*****\n\n"
            if error.code == -1022 {
                message += "It looks like you're using Xcode 7 and due to an App Transport Security issue (absence of SSL-based HTTP) the asset cannot be loaded from the specified URL: \"\(self.URL)\".\nTo fix this issue, append the following to your .plist file:\n\n<key>NSAppTransportSecurity</key>\n<dict>\n\t<key>NSAllowsArbitraryLoads</key>\n\t<true/>\n</dict>\n\n"
                fatalError(message)
            } else {
                fatalError("\(message)\(error.description)\n\n")
            }
        }
    }

Is the error is a 404 - a fatalError, which crashes a device, shouldn't be thrown. A log message would make more sense.

Do you agree? If so, I'll submit a PR.

teodorpatras commented 8 years ago

Code has been updated since. Have a look: https://github.com/teodorpatras/Jukebox/blob/master/Source/JukeboxItem.swift

samuelbeek commented 8 years ago

Sorry @teodorpatras, didn't see that! great work 👍