At some times, it is more practical to stream videos in your app rather than include them with the app, since the app will take a lot more storage on the device. In this tutorial, you can learn how to play a video from your server!

Let’s get started! For this tutorial, there is no starter project needed! Just create a single view application in Xcode, and we are ready to start! First, we will need to import AVKit at the top of the file. Then, in viewDidLayoutSubviews(), add the following code:

let player = AVPlayer(url: URL(string: "http://avikam.com/wp-content/uploads/2016/09/SpeechRecognitionTutorial.mp4")!)
let playerController = AVPlayerViewController()
playerController.player = player
self.present(playerController, animated: true) {
    player.play()
}

Before we can run, there is one more small step: We have to Allow Arbitrary Loads in the App Transport Security Settings. This allows websites without a secured connection to still be used in your iOS application. Your Info.plist file should look similar to the image below.

That’s it for this tutorial! Here is the finished project. I hope you enjoyed this tutorial, and if you have any questions or comments, feel free to join the discussion below! Come back for some more tutorials on iOS Development!