How to run You tube Video in Xcode?


How to run You tube Video in Xcode?

Here we have to create a WebView in which you have to use the html tag to embedded the Youtube Url.
Here the code :
In interface just declare
UIwebView * _webView;
In implementation (.m file)
– (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];
_webView.allowsInlineMediaPlayback = YES;
_webView.mediaPlaybackRequiresUserAction = NO;
[self.view addSubview:_webView];

NSString* embedHTML = [NSString stringWithFormat:@”function onYouTubeIframeAPIReady(){ytplayer=new YT.Player(‘playerId’,{events:{onReady:onPlayerReady}})}function onPlayerReady(a){ a.target.playVideo(); }”, @”SbPFDcspRBA”];
[_webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];

UIButton* pauseButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 375, 100, 50)];
[pauseButton setTitle:@”Pause” forState:UIControlStateNormal];
[pauseButton addTarget:self action:@selector(pauseVideo:) forControlEvents:UIControlEventTouchUpInside];
pauseButton.backgroundColor = [UIColor redColor];
[self.view addSubview:pauseButton];

}

-(IBAction)pauseVideo:(id)sender{
[_webView stringByEvaluatingJavaScriptFromString:@”ytplayer.pauseVideo()”];
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s