Search code examples
iosavplayeravplayerlayer

iOS - AVPlayer doesn't play mov file


I have the following code which is not working with the mov file, but it works when i use an MP4 file. The important thing about to mov file is because it has an alpha channel. I'm open to find solutions that offers me an alpha channel as mov file does.

class MovViewController: UIViewController {
    var avPlayer: AVPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()
        let filepath: String? = Bundle.main.path(forResource: "animacion_logo", ofType: "mov")
        let fileURL = URL.init(fileURLWithPath: filepath!)


        let player = AVPlayer(url: fileURL)
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.view.bounds
        //        self.view.layer.addSublayer(playerLayer)
        self.view.layer.insertSublayer(playerLayer, at: 0)
        player.play()

    }
}

This is the original mov file: https://ufile.io/jcbfn


Solution

  • AVPlayer do not support ProRes format with alpha: Using AVPlayer to view transparent video

    But there is some options out there. Take a look at this Medium post: https://medium.com/@quentinfasquel/ios-transparent-video-with-coreimage-52cfb2544d54