Embedding videos in iOS app

Viewed 2446

I'm fairly new to iOS development, but I'm confident with the basics (basic interface, user interaction, logic). What I want to do now is create an app that streams/downloads a video from a personal recording website (so login required by user), and then allows basic editing (trimming) and sharing to different social media, like twitter, facebook, youtube, etc... I have absolutely no experience with this.

My research so far has pointed me towards webViews and use of AVKit import, and they seem appropriate, but I was hoping for more concrete advice. What do I look into? Where can I start?

1 Answers

Its pretty easy to give a URL to AVPlayer and have it stream a video into the layer. I usually add the layer into a view and use autolayout on that view to resize it (although you can also subclass UIView and override layerClass and make the videoLayer the view's backing layer if you want). This code will stream from a remote URL or if you download the file to the documents directory and get a URL to it you can play a local file also.

        let playerLayer = AVPlayerLayer()
        let player = AVPlayer(playerItem: AVPlayerItem(asset: AVAsset(url: url), automaticallyLoadedAssetKeys: ["playable"]))
        playerLayer = AVPlayerLayer(player: player)
        playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
        playerLayer.frame = videoView.bounds
        videoView.isHidden = false
        videoView.layer.addSublayer(playerLayer) 
        playerLayer.player?.play()
Related