How to Make the Use of YouTube Player in Swift?

This article explains the use of Youtube Player in Swift. You will learn how iOS developers India make the use of Youtube player and see videos in iOS application.
Loading...

This article explains the use of Youtube Player in Swift. You will learn how iOS developers India make the use of Youtube player and see videos in iOS application.

One liner: In this tutorial we will learn about how to play YouTube video in iOS app. This tutorial is implemented in Xcode 8 and it built for iOS 10.

Start with creating one single view application with product name “YoutubeVideoPlayer”. In language field select swift language and devices field select universal.

In this tutorial we use YouTube Helper Library created by Google and open source, which you can download from here. After that go to download folder and select YTPlayerview.h, YTPlayerView.m, the Assets file. Drag the selected file to our project and select “Copy items into destination group’s folder”. Check below screenshot.

1               2

First, go to File -> New -> File -> iOS -> header file and add to our project. After that import objective c file “YTPlayerview.h”. Now go to Main.storybord and add one view from object library to main view.  Next go to Identity Inspector and change class name to YTPlayerView. Ctrl + drag from view to ViewController and make connection of IBOutlet as “viewYouTube”. Next add two buttons with title “Stop” and “Play” respectively. Ctrl + drag from buttons to ViewController and make connection of IBAction as btnStopClick and btnPlayClick respectively. Please check below screenshot for more info.

3 4

Now go to ViewController.swift class and in viewDidLoad() method pass one video id to YTPlayerView variable. Check this below screenshot.

5

Next is play and stop method. In btnPlayClick() call playVideo method for start player and btnStopClick() call stopVideo method for stop player. These things are show in below screenshot.

6

Now build and run project. If everything is correct, your app should run properly and you will see below output. You can play video in full screen and half screen. Also you can stop and play from default buttons or our custom buttons.

7 8

So, you can play and see youtube videos in iOS application by using Youtube Player API in Swift. IOS developers India have explained the method to use Youtube Player API in Swift. If you want to ask anything, you can make comments below.

1122 Total Views 3 Views Today
Loading...


Vijay is a compulsive blogger who likes to educate like-minded people on various new technologies and trends. He works with Aegis SoftTech as a software developer and has been developing software for years. Stay Connected to him on Facebook and Google+.