视频在UIWebView中自动播放 [英] Video playing automatically in UIWebView

查看:91
本文介绍了视频在UIWebView中自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I have a webview and when i tried to load the video files in that , it starts playing the video automatically without user intervention. And also the play button is still displayed in webview (video is playing behind that). I am using the following code to load the URL

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

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

Can you tell me how to disable the play button OR the Video should start playing only after the user taps the play button ??

推荐答案

- (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.

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

I hope this may help you and better way for your purpose.

这篇关于视频在UIWebView中自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆