How to play a MP4 video on the launch screen when the app loads

You can create a custom ViewController for "Main Interface" and use it after the LaunchScreen with use AVPlayer inside. In swift will be something like this:

var player: AVPlayer?

override func viewDidLoad() {
    super.viewDidLoad()

    loadVideo()
}

private func loadVideo() {

    //this line is important to prevent background music stop
    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
    } catch { }

    let path = NSBundle.mainBundle().pathForResource("your path", ofType:"mp4")

    player = AVPlayer(URL: NSURL(fileURLWithPath: path!))
    let playerLayer = AVPlayerLayer(player: player)

    playerLayer.frame = self.view.frame
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    playerLayer.zPosition = -1

    self.view.layer.addSublayer(playerLayer)

    player?.seekToTime(kCMTimeZero)
    player?.play()
}

Tags:

Ios

Swift