我试图从照片库导出视频,但是从未执行导出回调。我会定期检查导出进度,进度始终为零。
以下代码可在99.9%的情况下工作,但有时在某些设备上(绝对随机),它会停止工作,只有重新启动iPhone才有帮助。
AVAssetExportSession.Status
一直处于waiting
状态
class FilesInteractor { static func tempDirectoryPath() -> String { let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString return documentsPath.appendingPathComponent("temp") as String } static func createTempDirectory() { if !FileManager.default.fileExists(atPath: tempDirectoryPath()) { try? FileManager.default.createDirectory(atPath: tempDirectoryPath(), withIntermediateDirectories: true, attributes: nil) } } static func testVideoURL(name: String, ext: String = "mov") -> URL { createTempDirectory() let outputURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("test").appendingPathComponent("\(name).\(ext)", isDirectory: false) log.debug("Test video URL: \(outputURL)") return outputURL } }
import AVFoundation let asset = AVAsset() let outputURL = FilesInteractor.testVideoURL("output") let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPreset1280x720) exportSession?.outputFileType = .mov exportSession?.outputURL = outputURL try? FileManager.default.removeItem(at: outputURL) exportSession?.exportAsynchronously(completionHandler: { print("sometimes never calls") })
其他视频应用程序也冻结(Filto,Videoleap):