添加Youtube视频片段

时间:2012-01-13 17:37:59

标签: iphone objective-c cocoa-touch

这样可以正常工作,但它首先显示缩略图视图,我必须单击它才能播放视频。所以我需要删除此缩略图视图,并直接播放视频。我怎样才能做到这一点。我的代码如下;

- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
    {
  if (self = [super init]) 
  {
    // Create webview with requested frame size
    self = [[UIWebView alloc] initWithFrame:frame];

    // HTML to embed YouTube video
    NSString *youTubeVideoHTML = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 480\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"> <div><object width=\"480\" height=\"256\"> <param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param><param name=\"wmode\" value=\"transparent\"></param> <embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"480\" height=\"256\"></embed> </object></div></body></html>";

    // Populate HTML with the URL and requested frame size
    NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];

    // Load the html into the webview
    [self loadHTMLString:html baseURL:nil];


}
  return self;  
}

1 个答案:

答案 0 :(得分:1)

使用自动播放参数。所有参数都描述为here