Youtube - iPhone - 显示视频的UIWebView

cha*_*nce 2 youtube iphone sdk uiwebview

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

这就是我现在所拥有的,我正在寻找以编程方式删除部分(它给出维度并可能用UIWebView替换它),因此我可以即兴使用IB,这将有助于我的应用程序启动时,快速动画发生,然后我想在viewDidLoad完成后加载和显示此youtube链接.

.h文件:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame;
Run Code Online (Sandbox Code Playgroud)

.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];
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢!! 谢谢

小智 7

这可以使用在IB中创建的UIWebViews:

.h文件:

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

-(void)embedYouTubeInWebView:(NSString*)url theWebView: (UIWebView *)aWebView;
Run Code Online (Sandbox Code Playgroud)

.m文件:

在viewDidLoad中:

[self embedYouTubeInWebView:youTubeString theWebView:infoVideo1];
Run Code Online (Sandbox Code Playgroud)

方法:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

您甚至可以在一个屏幕上拥有多个webView.希望这可以帮助.