开发者

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

开发者 https://www.devze.com 2023-02-20 02:05 出处:网络
On my app I need a button, so when it\'s tapped a youtube video is launched. 开发者_高级运维So how can I achieve this?The iOS device has URL schemes that it recognize.Build your youTube url like the

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

开发者_高级运维

So how can I achieve this?


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.


You could try this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com"]];


I believe in Black Frog's answer, sharedInstance should be changed to sharedApplication like this:

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];


I'm not an expert on that particular subject, but have you checked in the youTube developper kits. I think there is some Cocoa stuffs...

Another way is to create a webview that you point to a webpage containing only your video. I guess it is a working solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号