2011-01-18 148 views
2

我的应用程序中有一个脚本在UIView的一部分中加载Youtube链接,该链接由我的服务器(mySQL /使用php)提供,并从中载入。 ..这个脚本下面工作正常.....但是...Youtube-iPhone-显示视频UIWebView

这是我现在有什么,我正在寻找删除程序化的部分(它给出的尺寸,并可能取代它与UIWebView)所以我可以即兴使用IB,这将有助于我的应用程序启动时,发生快速动画,然后我希望这个youtube链接加载并在viewDidLoad完成后显示。

.h文件中:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame; 

.m文件

//view did load function... 

[self embedYouTube:youtubestring frame:CGRectMake(69,72,184,138)]; 

//after the view did load is closed I have.. 

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame { 
NSString *embedHTML = @"\ 
<html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color: transparent;\ 
color: white;\ 
}\ 
</style>\ 
</head><body style=\"margin:0\">\ 
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
</body></html>"; 
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height]; 
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame]; 
[videoView loadHTMLString:html baseURL:nil]; 
[self.view addSubview:videoView]; 
[videoView release]; 
} 

任何帮助将大大感激!谢谢

回答

1

艾姆,iPhone没有Flash。它从来没有,也许永远不会有。在iPhone上打开YouTube视频的唯一方法是通过YouTube应用,以其他格式播放。对于这样的一个例子是 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com /v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"]];
您可以在这里找到更多的细节:http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

+0

其实我的代码现在工作开不起来了youtube的应用程序,实际上播放youtube视频(从应用程序内),只是说,它在应用程序商店...它只是使用CGRect,而不是界面生成器....我明白iPhone不支持Flash,然而,他们认为他们可能是一种解决方法...谢谢,虽然... – chance 2011-01-18 23:14:19

+0

这个链接告诉你如何嵌入你管视频:http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-移动apps.html – 2012-05-14 04:53:58

7

这个工程使用IB创建UIWebViews中:

.h文件:

@property (nonatomic, retain) IBOutlet UIWebView *infoVideo1; 

-(void)embedYouTubeInWebView:(NSString*)url theWebView: (UIWebView *)aWebView; 

.m文件:

in viewDidLoad:

[self embedYouTubeInWebView:youTubeString theWebView:infoVideo1]; 

方法:

- (void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {  

NSString *embedHTML = @"\ 
<html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color: transparent;\ 
color: white;\ 
}\ 
</style>\ 
</head><body style=\"margin:0\">\ 
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
</body></html>"; 

NSString* html = [NSString stringWithFormat:embedHTML, url, aWebView.frame.size.width, aWebView.frame.size.height]; 

[aWebView loadHTMLString:html baseURL:nil]; 
} 

你甚至可以有一个单一的屏幕上的多个网页视图。希望这可以帮助。