我希望使用Objective-C自动播放一段从特定时间开始的Youtube视频。
我使用了以下代码:
但是视频没有自动播放。我做错了什么?我该如何解决?
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"%s",__FUNCTION__);
appDelegate = (AppDelegate *) [[UIApplication sharedApplication]delegate];
float width = 309.0f;
float height = 196.0f;
NSString *youTubeURL = @"http://www.youtube.com/embed/Gyf1kjaUZCo?autoplay=1";
UIWebView *wv = [[UIWebView alloc] init];
wv.frame = CGRectMake(0, 0, width, height);
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1];
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"%f\" height=\"%f\" src=\"http://www.youtube.com/embed/Gyf1kjaUZCo?autoplay=1\" allowfullscreen frameborder=\"0\"></iframe>", width, height];
[html appendString:@"</body></html>"];
[wv loadHTMLString:html baseURL:nil];
[self.videoView addSubview:wv];
}
但是视频没有自动播放。我做错了什么?我该如何解决?