我真的很想让图像或文字真正成为我视频的一部分,类似于Snapchats添加文字/贴纸功能。我不希望它只是坐在我的视频之上,但实际上是在视频本身,所以当它保存时,它显示。任何帮助将受到高度赞赏并标记为答案。多谢你们。代码如下......
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()
}