recherche

Maison  >  Questions et réponses  >  le corps du texte

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

怎样用 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 = @"<html><head lang=\"en\"><meta charset=\"UTF-8\"><title></title></head><body>";
    NSString *str2 = @"</body></html>";
    
    NSString *content = @"<embed type=\"application/x-shockwave-flash\" class=\"edui-faked-video\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"http://player.youku.com/player.php/sid/XMTcxNzM3MzE2MA==/v.swf?beta&f=27865525&o=1&spm=0.0.m_213480.5~5~5~5~5~5!2~5~5!2~A.2aTtJI&from=y1.3-music-new-140-21793.213123-213237-213480.2-1#paction\" width=\"420\" height=\"280\" wmode=\"transparent\" play=\"true\" loop=\"false\" menu=\"false\" allowscriptaccess=\"never\" allowfullscreen=\"true\"/>";
    
    NSString * html = [NSString stringWithFormat:@"%@%@%@",str1,content,str2];
    
    [web loadHTMLString:html baseURL:nil];

请问如何实现?多谢多谢

怪我咯怪我咯2772 Il y a quelques jours705

répondre à tous(1)je répondrai

  • 高洛峰

    高洛峰2017-04-18 09:37:55

    - (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];
    

    réf : http://stackoverflow.com/ques...

    répondre
    0
  • Annulerrépondre