I am composing a video using AVMutableComposition. I need to add text overlay at different time intervals. i,e.
I am using the below code to add text overlay but its static and stays through out the video.
let parentLayer = CALayer()
parentLayer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let videoLayer = CALayer()
videoLayer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let subtitleText = CATextLayer()
subtitleText.font = font
subtitleText.frame = CGRect(x: 0, y: 100, width: size.width, height: 50)
subtitleText.string = "hhh"
subtitleText.alignmentMode = kCAAlignmentCenter
subtitleText.foregroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1).cgColor
subtitleText.displayIfNeeded()
parentLayer.addSublayer(videoLayer)
parentLayer.addSublayer(subtitleText)
Any help is highly appreciated.
If anyone needs answer for this, am sorry I couldn't find a direct solution, so i did a costly work around.