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.
精彩评论