html5 - iOS 开发 使用 UIWebView 加载 HTML 标签内嵌视频

 粉雪琪的天涯 发布于 2022-10-28 13:07

怎样用 UIWebView 的 loadHTML 方法加载一段 HTML 标签实现视频播放?
后台返回HTML 标签,内嵌视频,可以用浏览器打开,但是用 UIWebView 没有反应。代码如下

    UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:web];
    web.allowsInlineMediaPlayback = YES;
    web.delegate = self;
    self.web = web;
    
    NSString *str1 = @"";
    NSString *str2 = @"";
    
    NSString *content = @"";
    
    NSString * html = [NSString stringWithFormat:@"%@%@%@",str1,content,str2];
    
    [web loadHTMLString:html baseURL:nil];

请问如何实现?多谢多谢

1 个回答
  • - (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];
    

    ref: http://stackoverflow.com/ques...

    2022-11-12 01:45 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有