背景に動画を置く方法
画面の背景に動画をリピートで再生させ続けたい場合
viewController.swift
import UIKit
import AVFoundation
class PopupDetailViewController: UIViewController {
var player = AVPlayer()
let path = Bundle.main.path(forResource: "Sample", ofType: "mov")
override func viewDidLoad() {
super.viewDidLoad()
player = AVPlayer(url: URL(fileURLWithPath: path!))
player.play()
let playerLayer = AVPlayerLayer(player: player)
// フレームの大きさを決める
playerLayer.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
playerLayer.videoGravity = .resizeAspectFill
playerLayer.repeatCount = 0
playerLayer.zPosition = -1
view.layer.insertSublayer(playerLayer, at: 0)
// リピートさせる
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { (notification) in
self.player.seek(to: .zero)
self.player.play()
}
}
動画の保存場所
ここにファイルを移せば再生される