Youtube - iPhone - 显示视频的UIWebView [英] Youtube - iPhone - displaying UIWebView of video
问题描述
我的应用程序中有一个脚本,它在UIView的一部分中加载Youtube链接,该链接由我的服务器(mySQL /使用php)提供,并且从中加载...下面的这个脚本工作正常。 ....但是......
I have a script in my app that loads a Youtube link in a section of the UIView, the link is provided by my server (mySQL/using php) and from that it is loaded... this script below works fine..... however...
这是我现在所拥有的,我正在寻找以编程方式删除部分(它给出尺寸并可能用以下内容替换它)一个UIWebView),所以我可以即兴使用IB,这将有助于我的应用程序启动时,发生快速动画,然后我想在viewDidLoad完成后加载和显示这个youtube链接。
Here is what I have right now, I was looking to remove the programmatically part (where it gives the dimensions and possibly replace it with a UIWebView) to it, so I could improvise using IB, this will help when my application launches, a quick animation occurs and then I want this youtube link to load and display after viewDidLoad is completed.
.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];
}
任何帮助都将不胜感激!谢谢
any help would greatly be appreciated!! thanks
推荐答案
这可以使用在IB中创建的UIWebViews来实现:
This works using UIWebViews created in IB:
.h文件:
@property (nonatomic, retain) IBOutlet UIWebView *infoVideo1;
-(void)embedYouTubeInWebView:(NSString*)url theWebView: (UIWebView *)aWebView;
.m文件:
in viewDidLoad:
in the 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];
}
您甚至可以在一个屏幕上拥有多个webView。希望这会有所帮助。
You can even have multiple webViews on a single screen. Hope this helps.
这篇关于Youtube - iPhone - 显示视频的UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!