Saturday, 9 December 2017

AVKit Player


First, Allow Internet perission in info.plist

Info.plist -> Add (+) -> App Transport Security Setting -> Add(+) ->
Allow Arbitary Load -> YES



1. Dynamic create AVPlayer - Just normal player

------------------------------------------------------
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        let player = AVPlayer(url: videoURL!)
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.view.bounds
        self.view.layer.addSublayer(playerLayer)

        player.play()
------------------------------------------------------

2. Dynamic create AVPlayerViewController - With full functionality (Play, Stop, Mute)

------------------------------------------------------
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        let player = AVPlayer(url: videoURL!)
        let playerViewController = AVPlayerViewController()
        playerViewController.player = player
        self.present(playerViewController, animated: true) {
            playerViewController.player!.play()

        }
------------------------------------------------------



22

No comments:

Post a Comment