Q:

Autoplaying an MP4 video in a UIView that is on loop like a GIF?

Once users go to this specific page, I want the video to immediately start playing inside of a UIView with no controls. It will just loop like a gif. This is code I found off of github and it doesn't seem to work. It just shows the white UIView when I pull up the page. My file name is correct as well.
import Foundation
import UIKit
import AVKit
import AVFoundation

class RampWallPush: UIViewController {

@IBOutlet weak var videoView: UIView!

var player: AVPlayer?

override func viewDidLoad() {
    super.viewDidLoad()

    // Load video resource
    if let videoUrl = Bundle.main.url(forResource: "small", withExtension: "mp4") {

        // Init video
        self.player = AVPlayer(url: videoUrl)
        self.player?.isMuted = true
        self.player?.actionAtItemEnd = .none

        // Add player layer
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        playerLayer.frame = view.frame

        // Add video layer
        self.videoView.layer.addSublayer(playerLayer)

        // Play video
        self.player?.play()

        // Observe end
        NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidReachEnd), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.player?.currentItem)
    }
}

// MARK: - Loop video when ended.
@objc func playerItemDidReachEnd(notification: NSNotification) {
    self.player?.seek(to: CMTime.zero)
    self.player?.play()
}

}

A:

Your code is works you need to verify the file exists in your project and .......
    // Load video resource
  if let videoUrl = Bundle.main.url(forResource: "sample", withExtension: "mp4") {
        // exists
  }
  else {

     print("NoFile")
  }

So select the file and 

You need to change the frame 
 playerLayer.frame = CGRect(x:0,y:0,width:200,height:300) 
 self.videoView.layer.addSublayer(playerLayer)
 playerLayer.center = videoView.center 

Created a demo Here

