2014-12-03 71 views

回答

0

请试试这个代码工作对我来说

String item = "http://www.youtube.com/embed/"; 

String ss = "your url"; 
ss = ss.substring(ss.indexOf("v=") + 2); 
item += ss; 
DisplayMetrics metrics = getResources().getDisplayMetrics(); 
int w1 = (int) (metrics.widthPixels/metrics.density), h1 = w1 * 3/5; 
wv.getSettings().setJavaScriptEnabled(true); 
wv.setWebChromeClient(chromeClient); 
wv.getSettings().setPluginsEnabled(true); 

try { 
    wv.loadData(
    "<html><body><iframe class=\"youtube-player\" type=\"text/html5\" width=\"" 
    + (w1 - 20) 
    + "\" height=\"" 
    + h1 
    + "\" src=\"" 
    + item 
    + "\" frameborder=\"0\"\"allowfullscreen\"></iframe></body></html>", 
          "text/html5", "utf-8"); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

private WebChromeClient chromeClient = new WebChromeClient() { 

    @Override 
    public void onShowCustomView(View view, CustomViewCallback callback) { 
     super.onShowCustomView(view, callback); 
     if (view instanceof FrameLayout) { 
      FrameLayout frame = (FrameLayout) view; 
      if (frame.getFocusedChild() instanceof VideoView) { 
       VideoView video = (VideoView) frame.getFocusedChild(); 
       frame.removeView(video); 
       video.start(); 
      } 
     } 

    } 
}; 
相关问题