Am using below code for decrypting the VideoFile.mp4(CTR/Nopadding encrypted file) and playing it in Avplayer. This code works for small files. But its crashing for big video files due to memory issues.
How to solve this issue. Please help
guard let content = Bundle.main.url(forResource: "videoFile", withExtension: "mp4") else{
return
}
let vidoeData = NSData(contentsOf: content)!
let vidoeDatadencrypted = vidoeData.decryptData(vidoeData as Data, withKey: aeskey.data(using: .utf8))
let tmpFileURL1 = URL(fileURLWithPath:NSTemporaryDirectory()).appendingPathComponent("video").appendingPathExtension("mp4")
let wasFileWritten1 = (try? vidoeDatadencrypted!.write(to: tmpFileURL1, options: [.atomic])) != nil
if wasFileWritten1{
let player = AVPlayer(url: tmpFileURL1)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
}
update:
Able to achive this for smaller files using the above shared code.
how to load avplayer with NSStream?