I am composing a video using AVMutableComposition. I need to add text overlay at different time intervals. i,e.
- display string "abc" from 0sec to 2sec hide afterwards
- display string "xyz" from 1sec to 1.5sec hide afterwards
- display string "qwe" from 2sec to 5sec
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.