我使用AVFoundation
合并了视频,并发现了一个似乎有时间刻度损坏的视频。该视频在点击"选择"时会产生错误。在UIImagePickerController
。一旦"选择"系统错误就会打印出来。按钮被点击,但是应用程序崩溃直到下面的注释行才会发生。崩溃发生在加载无法加载的资产时,因为它是零值。
如何捕获此错误以通知用户该问题并防止崩溃?
2017-07-31 14:22:18.284542-0500 APP [2299:62163] [Generic]视频导出资产失败:错误Domain = AVFoundationErrorDomain Code = -11821"无法解码" UserInfo = {NSLocalizedDescription =无法解码,NSLocalizedFailureReason =媒体数据无法解码。它可能已损坏。}
extension videoViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
dismiss(animated: true, completion: nil)
let mediaInfo = info
print("Media Info: ", mediaInfo)
if mediaType == kUTTypeMovie {
//ERROR THROWS AT BELOW LINE
let avAsset = AVAsset(url:info[UIImagePickerControllerMediaURL] as! URL)
//var message = ""
if loadingAssetOne {
//message = "Video one loaded"
firstAsset = avAsset
} else {
//message = "Video two loaded"
secondAsset = avAsset
//set bg image
videoPreviewUIImage(assetName: avAsset as! AVURLAsset)
}
//let alert = UIAlertController(title: "Asset Loaded", message: message, preferredStyle: .alert)
//alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil))
//present(alert, animated: true, completion: nil)
}
}
}