下载文件后,我已使用RNCryptor库对视频文件(.mov)进行了加密。现在,我想使用AVPlayer播放此视频文件。当我解密文件时,它返回NSData。如何在AVPlayer中使用NSData播放视频。
对于加密,我添加了以下代码:-
let fm = FileManager.default
guard let docUrl = fm.urls(for: .documentDirectory, in: .userDomainMask).first else {
print("Unable to reach the documents folder")
return
}
let localUrl = docUrl.appendingPathComponent(String.init(format: "%@", downloadModel.fileName))
let data = try Data.init(contentsOf: localUrl)
let password = "secret"
let cipherText = RNCryptor.encrypt(data: data, withPassword: password)
用于解密视频文件
let cipherText = UserDefaults.sharedInstance.getCipherText()
// Decryption
do {
let originalData = try RNCryptor.decrypt(data: cipherText, withPassword: "secret")
debugPrint(originalData)
let dataString = String.init(data: originalData, encoding: .utf16)
let url = URL.init(string: dataString!)
configureVideoPlayer(url: url!)
} catch {
print(error)
}
但url为零。我该如何做到这一点。