I am really struggling with getting an image or text to actually be a part of my video, similar to Snapchats add text/stickers feature. I don't want it to just sit on top of my video but actually be on the video itself so when it is saved, it shows. Any help would be highly appreciated and marked as answer. Thanks guys. Code is below...
import UIKit
import AVFoundation
import AVKit
import Photos
class VideoViewController: UIViewController {
override var prefersStatusBarHidden: Bool { return true }
var videoURL: URL
var player: AVPlayer?
var playerLayer: AVPlayerLayer?
init(videoURL: URL) {
self.videoURL = videoURL
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.keyWindow?.backgroundColor = .black
self.view.backgroundColor = .black
self.player = AVPlayer(url: videoURL)
self.playerLayer = AVPlayerLayer(player: self.player)
self.playerLayer?.frame = self.view.frame
self.playerLayer?.backgroundColor = UIColor.black.cgColor
self.view.layer.addSublayer(playerLayer!)
guard player != nil else { return }
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
player?.play()
}