Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch a YouTube video in my iPhone app?

On my app I need a button, so when it's tapped a youtube video is launched.

So how can I achieve this?

like image 829
LAA Avatar asked Mar 25 '11 23:03

LAA


2 Answers

The iOS device has URL schemes that it recognize. Build your youTube url like the following:

http://www.youtube.com/watch?v=VIDEO_IDENTIFIER

That will launch the youTube player on the device.

NSString *videoName = @"1JynBEX_kg8";
NSString *string = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@", videoName];
NSURL *url = [NSURL URLWithString:string];
UIApplication *app = [UIApplication sharedApplication];
[app openURL:url];

For more information on iOS URL Scheme Apple URL Scheme Reference.

like image 122
Black Frog Avatar answered Oct 21 '22 21:10

Black Frog


You could try this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com"]];
like image 23
Oscar Gomez Avatar answered Oct 21 '22 21:10

Oscar Gomez