AVFoundation

AVPlayer: 

An AVPlayer is not a view; rather, an AVPlayer’s content is made visible through a CALayer subclass, AVPlayerLayer, which can be added to your app’s interface.

An AV Foundation video playback inter‐ face can be wrapped in a simple view controller, AVPlayerViewController: you provide an AVPlayer, and the AVPlayerViewController automatically hosts an asso‐ ciated AVPlayerLayer in its own main view, providing standard playback transport controls so that the user can start and stop play, seek to a different frame, and so forth. AVPlayerViewController is provided by the AVKit framework; you’ll need to import AVKit.

play video:

//play video
        let url = Bundle.main.url(forResource:"movie", withExtension:"mov")!
        let asset = AVURLAsset(url:url)
        
        let player = AVPlayer(url: url)
        vc.player = player
        
        vc.view.frame = self.view.frame
        self.addChild(vc)
        self.view.addSubview(vc.view)
        vc.didMove(toParent: self)

New in iOS 13, the AVPlayerViewController’s delegate (AVPlayerViewController‐ Delegate) can be notified when the user enters and exits fullscreen mode. There are

two relevant delegate methods; when you build against iOS 13, they are backward compatible to iOS 12: 

• playerViewController(_:willBeginFullScreenPresentationWithAnimation- Coordinator:)

• playerViewController(_:willEndFullScreenPresentationWithAnimation- Coordinator:)

 

852 thoughts on “AVFoundation

Leave a Reply

Your email address will not be published. Required fields are marked *