视频在UIWebView中自动播放

时间:2012-04-03 11:56:13

标签: iphone ios xcode uiwebview

嗨我有一个webview,当我尝试加载视频文件时,它会自动开始播放视频而无需用户干预。并且播放按钮仍然显示在webview中(视频正在后面播放)。我使用以下代码加载URL

NSURL*  url = [NSURL fileURLWithPath:filePath];
NSURLRequest*   request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

你能告诉我如何禁用播放按钮或者视频应该在用户点击播放按钮后开始播放吗?

1 个答案:

答案 0 :(得分:6)

- (void)videoThumb:(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];

  [webView loadHTMLString:html baseURL:nil];
  [self.view addSubview:webView];
  [webView release];
}

//Include above function to your page and call it by passing the urlstring
[self videoThumb:url:frame];


//frame : this parameter needs the size of the thumb you want to use.

我希望这可以帮助你,更好地实现你的目的。