0

下载文件后,我使用 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)
        }

但网址为零。我怎么能做到这一点。

4

0 回答 0