Youtube视频框架在iOS 6中不显示或播放

时间:2012-11-19 02:57:12

标签: iphone ios xcode sdk youtube

我有一个现有应用程序的问题,问题是应用程序在UIScrollView中的应用程序中播放Youtube视频但在我安装了新的Xcode SDK 4.5.2后,这些视频有一个空白的白色方块而它们不是当我点击它们时,就像以前一样工作,这是我在我的应用程序中的代码:

- (void)playVideo:(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.scrollView addSubview:videoView];
[videoView release];
NSLog(@"%@",html);
}

- (void)viewDidLoad
{

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 20, 110, 110)];

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 170, 110, 110)];

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 320, 110, 110)];

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 470, 110, 110)];

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 620, 110, 110)];

[self playVideo:@"http://www.youtube.com/...." frame:CGRectMake(5, 765, 110, 110)];


[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320,1400)];

[super viewDidLoad];
}

我不知道在这段代码中需要更改什么才能让它们出现并再次播放。

1 个答案:

答案 0 :(得分:0)

我为我的问题找到了解决方案。我需要在代码中更改的唯一内容是替换此代码:

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 *embedHTML = @"<body style=\"margin:0\"> <iframe height=\"110\" width=\"110\"        src=\"http://www.youtube.com/embed/HERE YOU PUT THE ID OF YOUR VIDEO\"   frameborder=\"0\"/></iframe></body> ";