如何在iPhone应用中发布YouTube视频?

时间:2022-12-08 07:20:06

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

在我的应用程序上,我需要一个按钮,所以当它被点击时,会启动YouTube视频。

So how can I achieve this?

那我该怎么做呢?

4 个解决方案

#1


11  

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

iOS设备具有可识别的URL方案。像下面这样构建你的youTube网址:

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

That will launch the youTube player on the device.

这将在设备上启动youTube播放器。

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.

有关iOS URL Scheme Apple URL Scheme Reference的更多信息。

#2


3  

You could try this:

你可以试试这个:

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

#3


1  

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

我相信Black Frog的回答,sharedInstance应该改为sharedApplication,如下所示:

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

#4


0  

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...

我不是那个特定主题的专家,但你已经检查了youTube开发者工具包。我觉得有一些Cocoa的东西......

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

另一种方法是创建一个webview,指向仅包含视频的网页。我想这是一个有效的解决方案。

#1


11  

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

iOS设备具有可识别的URL方案。像下面这样构建你的youTube网址:

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

That will launch the youTube player on the device.

这将在设备上启动youTube播放器。

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.

有关iOS URL Scheme Apple URL Scheme Reference的更多信息。

#2


3  

You could try this:

你可以试试这个:

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

#3


1  

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

我相信Black Frog的回答,sharedInstance应该改为sharedApplication,如下所示:

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

#4


0  

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...

我不是那个特定主题的专家,但你已经检查了youTube开发者工具包。我觉得有一些Cocoa的东西......

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

另一种方法是创建一个webview,指向仅包含视频的网页。我想这是一个有效的解决方案。