2017-03-03 207 views
0

你好,我正在android應用程序中,我想播放vimeo視頻,我從json中獲取API的響應並使用webview播放視頻,並且播放效果很好,但是Webview是顯示非常小,播放視頻也小我的問題是在Android中播放Vimeo視頻,包含iframe的視頻url

  1. 我想播放視頻寬度可根據Android設備的寬度。我可以從Displaymetrics得到它,但如何設置爲iframe?
  2. 我想膨脹播放視頻的媒體控制器的自定義視圖。 喜歡玩暫停圖標自定義控制器

我在VIDEO_ID得到這種URL響應從API

<iframe src="https://player.vimeo.com/video/video_id" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> 

我得到的視頻ID

下面是我用

代碼
webView.setWebChromeClient(new WebChromeClient()); 
     webView.getSettings().setAllowFileAccess(true); 
     webView.getSettings().setPluginState(WebSettings.PluginState.ON); 
     webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND); 
     webView.setWebViewClient(new WebViewClient()); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.getSettings().setLoadWithOverviewMode(true); 
     webView.getSettings().setUseWideViewPort(true); 

     String data_html=getexplore_list.get(pos).getVideo_url(); 

     webView.loadDataWithBaseURL("http://vimeo.com", data_html, "text/html", "UTF-8", null); 

請提供任何解決方案或鏈接將不勝感激

回答

0

使用樣式HTML,

String url = "<iframe src=\"" + videoUrl + "\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"; 
0
mViewHolder.webView.getSettings().setJavaScriptEnabled(true); 
String yourData = "<div id='made-in-ny'></div>\n" + 
      "\n" + 
      "<script src='https://player.vimeo.com/api/player.js'></script>\n" + 
      "<script>\n" + 
      " var options = {\n" + 
      "  id: 59777392,\n" + 
      "  width: 540,\n" + 
      "  loop: true\n" + 
      " };\n" + 
      "\n" + 
      " var player = new Vimeo.Player('made-in-ny', options);\n" + 
      "\n" + 
      " player.setVolume(0);\n" + 
      "\n" + 
      " player.on('play', function() {\n" + 
      "  console.log('played the video!');\n" + 
      " });\n" + 
      "</script>"; 
mViewHolder.webView.loadData(yourData, "text/html; charset=utf-8", "UTF-8"); 

更改標識和寬度。這是工作。