Youtube Video Player


To play Youtube video within the app we have 2 ways:

1. Open Youtube App (if installed) or launch Safari to play video:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=Xk1zfQOklJY"]];

In this case we don't have a choice to bring back the user to our app.
So we better use the 2nd way.

2. Embed Youtube iOS Player Helper:
I have used youtube-ios-player-helper Version - 0.1.3
  1. Select YTPlayerView.hYTPlayerView.m, and the Assets folder from my Github repository CODE.
  2. Drag these files and folders into your project. Make sure the Copy items into destination group’s folder option is checked. When dragging the Assets folder, make sure that the Create Folder References for any added folders option is checked.
  3. Drag a UIView the desired size of your player onto your Storyboard.
  4. Change the UIView's class in the Identity Inspector tab to YTPlayerView
  5. Import "YTPlayerView.h" in your ViewController.
  6. Add the following property to your ViewController's header file:
    @interface ViewController : UIViewController <YTPlayerViewDelegate>
    @property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
  7. In Implementation's viewDidLoad() add following code:[self.playerView setDelegate: self];
    [self.playerView loadWithVideoId:@"Xk1zfQOklJY"];
  8. We are done.
  9. In case you want to get all the controls to Play, Pause, Stop, Seek to Time do download my code and check it out.

        Download - CODE


Below links helped me:
https://developers.google.com/youtube/v3/guides/ios_youtube_helper
https://github.com/youtube/youtube-ios-player-helper



Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0