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
YTPlayerView.m, and the Assets folder from my Github repository CODE.
- 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.
- Drag a UIView the desired size of your player onto your Storyboard.
- Change the UIView's class in the Identity Inspector tab to YTPlayerView
- Import "YTPlayerView.h" in your ViewController.
- Add the following property to your ViewController's header file:@interface ViewController : UIViewController <YTPlayerViewDelegate>@property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
- In Implementation's viewDidLoad() add following code:[self.playerView setDelegate: self];
- We are done.
- 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: