加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 在UIWebView中自动播放视频

发布时间:2020-12-14 17:49:35 所属栏目:百科 来源:网络整理
导读:嗨我有一个webview,当我尝试加载视频文件时,它开始自动播放视频而无需用户干预.并且播放按钮仍然显示在webview中(视频正在后面播放).我使用以下代码加载URL NSURL* url = [NSURL fileURLWithPath:filePath];NSURLRequest* request = [NSURLRequest requestWi
嗨我有一个webview,当我尝试加载视频文件时,它开始自动播放视频而无需用户干预.并且播放按钮仍然显示在webview中(视频正在后面播放).我使用以下代码加载URL

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

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

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读