【发布时间】:2011-07-04 07:24:15
【问题描述】:
我通过在 Internet 上找到的 sn-p 嵌入了来自 YouTube 的视频,这是我使用的代码:
@interface FirstViewController (Private)
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame;
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self embedYouTube:@"http://www.youtube.com/watch?v=l3Iwh5hqbyE" frame:CGRectMake(20, 20, 100, 100)];
}
- (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];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
它编译正确,当我打开它时,我看到一个位置不正确的白框,这是代码创建的。我有两个问题:
我怎么知道视频是否会播放,它只是一个普通的白框,模拟器会播放 YouTube 上的视频吗?
如何定位此框?
【问题讨论】:
-
这段代码在 iOS 6 中有效吗?
标签: iphone objective-c ios youtube